Browse Source

Add support for various server types

Mario Danic 8 năm trước cách đây
mục cha
commit
e6adc4fd95

+ 20 - 11
src/com/owncloud/android/ui/components/CustomEditText.java

@@ -33,7 +33,7 @@ import com.owncloud.android.authentication.AuthenticatorActivity;
  */
 
 public class CustomEditText extends android.support.v7.widget.AppCompatEditText {
-    private Rect mFixedRect = new Rect();
+    private Rect fixedRect = new Rect();
     private String fixedText = "";
     private boolean isPrefixFixed;
 
@@ -50,6 +50,11 @@ public class CustomEditText extends android.support.v7.widget.AppCompatEditText
             fixedText = "." + getResources().getString(R.string.server_url);
         }
 
+        if (TextUtils.isEmpty(fixedText)) {
+            setHint(R.string.auth_host_url);
+        }
+
+
     }
 
     public String getFullServerUrl() {
@@ -65,13 +70,7 @@ public class CustomEditText extends android.support.v7.widget.AppCompatEditText
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         if (!TextUtils.isEmpty(fixedText)) {
-            getPaint().getTextBounds(fixedText, 0, fixedText.length(), mFixedRect);
-
-            if (isPrefixFixed) {
-                mFixedRect.right += getPaint().measureText(fixedText);
-            } else {
-                mFixedRect.right += getPaint().measureText(fixedText);
-            }
+            getPaint().getTextBounds(fixedText, 0, fixedText.length(), fixedRect);
         }
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
@@ -81,12 +80,22 @@ public class CustomEditText extends android.support.v7.widget.AppCompatEditText
         super.onDraw(canvas);
         if (!TextUtils.isEmpty(fixedText)) {
             if (isPrefixFixed) {
-                canvas.drawText(fixedText, super.getCompoundPaddingLeft() + getPaint().measureText(fixedText),
+                canvas.drawText(fixedText, super.getCompoundPaddingLeft(),
                         getBaseline(), getPaint());
             } else {
-                canvas.drawText(fixedText, super.getCompoundPaddingLeft() + getPaint().measureText(getText().toString()),
-                        getBaseline(), getPaint());
+                canvas.drawText(fixedText, super.getCompoundPaddingLeft() + getPaint().measureText(
+                        getText().toString()), getBaseline(), getPaint());
             }
         }
     }
+
+    @Override
+    public int getCompoundPaddingLeft() {
+        if (!TextUtils.isEmpty(fixedText) && isPrefixFixed) {
+            return super.getCompoundPaddingLeft() + fixedRect.width();
+        } else {
+            return super.getCompoundPaddingLeft();
+        }
+    }
+
 }

+ 2 - 3
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -464,7 +464,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                     serverInputType.equals(SUBDOMAIN_SERVER_INPUT_TYPE)) {
                 mHostUrlInput.setText("");
             }
-
         } else {
             findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
             mRefreshButton = findViewById(R.id.centeredRefreshButton);
@@ -486,7 +485,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             public void afterTextChanged(Editable s) {
                 if (mOkButton.isEnabled() &&
                         !mServerInfo.mBaseUrl.equals(
-                                normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
+                                normalizeUrl(mHostUrlInput.getFullServerUrl(), mServerInfo.mIsSslConn))) {
                     mOkButton.setEnabled(false);
                 }
             }
@@ -867,7 +866,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
     private void checkOcServer() {
-        String uri = mHostUrlInput.getText().toString().trim();
+        String uri = mHostUrlInput.getFullServerUrl().trim();
         mServerIsValid = false;
         mServerIsChecked = false;
         mOkButton.setEnabled(false);

+ 0 - 1
src/main/res/layout/account_setup.xml

@@ -90,7 +90,6 @@
                     android:layout_gravity="bottom"
                     android:contentDescription="@string/auth_host_address"
                     android:drawablePadding="@dimen/alternate_half_padding"
-                    android:hint="@string/auth_host_url"
                     android:inputType="textUri"
                     android:paddingRight="@dimen/alternate_padding_right"
                     android:textColor="@color/login_text_color"

+ 2 - 2
src/main/res/values/setup.xml

@@ -19,11 +19,11 @@
     <string name ="user_agent">Mozilla/5.0 (Android) ownCloud-android/%1$s</string>
     
     <!-- URLs and flags related -->
-    <string name="server_url">nextcloud.com</string>
+    <string name="server_url"></string>
     <bool name="show_server_url_input">true</bool>
     <!-- Can be regular (full input), prefix (subdomain input) and suffix (directory input) -->
     <!-- Requires server url to be set -->
-    <string name="server_input_type">prefix</string>
+    <string name="server_input_type">regular</string>
     <bool name="show_welcome_link">true</bool>
 	<string name="welcome_link_url">"https://nextcloud.com/providers"</string>
 	<string name="share_api_link"></string>