فهرست منبع

Enforced servers

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 10 ماه پیش
والد
کامیت
4d587d3bf4

+ 19 - 0
app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java

@@ -20,6 +20,7 @@ import android.widget.TextView;
 
 import com.google.android.material.bottomsheet.BottomSheetBehavior;
 import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.nextcloud.android.common.ui.color.ColorUtil;
 import com.nextcloud.android.common.ui.theme.MaterialSchemes;
 import com.nextcloud.android.common.ui.theme.MaterialSchemesImpl;
@@ -37,6 +38,7 @@ import com.nextcloud.utils.EditorUtils;
 import com.owncloud.android.AbstractIT;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
+import com.owncloud.android.authentication.EnforcedServer;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProviderImpl;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -628,4 +630,21 @@ public class DialogFragmentIT extends AbstractIT {
             }
         }
     }
+    
+    @Test
+    public void testGson() {
+        ArrayList<EnforcedServer> t = new ArrayList<>();
+        t.add(new EnforcedServer("name", "url"));
+        t.add(new EnforcedServer("name2", "url1"));
+        
+        String s = new Gson().toJson(t);
+
+        ArrayList<EnforcedServer> t2 = new Gson().fromJson(s, new TypeToken<ArrayList<EnforcedServer>>() {
+        }.getType());
+
+        ArrayList<String> temp = new ArrayList<>();
+        for (EnforcedServer p : t2) {
+            temp.add(p.getName());
+        }
+    }
 }

+ 51 - 1
app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -40,9 +40,12 @@ import android.view.View;
 import android.view.inputmethod.EditorInfo;
 import android.webkit.CookieManager;
 import android.webkit.CookieSyncManager;
+import android.webkit.URLUtil;
 import android.webkit.WebResourceRequest;
 import android.webkit.WebResourceResponse;
 import android.webkit.WebView;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;
@@ -51,8 +54,10 @@ import android.widget.Toast;
 import com.blikoon.qrcodescanner.QrCodeActivity;
 import com.google.android.material.button.MaterialButton;
 import com.google.android.material.snackbar.Snackbar;
+import com.google.gson.Gson;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
 import com.nextcloud.android.common.ui.color.ColorUtil;
 import com.nextcloud.android.common.ui.theme.utils.ColorRole;
 import com.nextcloud.client.account.User;
@@ -115,6 +120,7 @@ import org.json.JSONObject;
 
 import java.io.InputStream;
 import java.net.URLDecoder;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -356,7 +362,51 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             /// initialize block to be moved to single Fragment to check server and get info about it
 
             /// initialize block to be moved to single Fragment to retrieve and validate credentials
-            initAuthorizationPreFragment(savedInstanceState);
+            if (TextUtils.isEmpty(getString(R.string.enforce_servers))) {
+                initAuthorizationPreFragment(savedInstanceState);
+            } else {
+                showAuthStatus();
+                accountSetupBinding.hostUrlFrame.setVisibility(View.GONE);
+                accountSetupBinding.hostUrlInputHelperText.setVisibility(View.GONE);
+                accountSetupBinding.scanQr.setVisibility(View.GONE);
+                accountSetupBinding.multipleServersLayout.setVisibility(View.VISIBLE);
+
+                ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.enforced_servers_spinner);
+                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+                ArrayList<String> servers = new ArrayList<>();
+                servers.add("");
+                adapter.add(getString(R.string.please_select_a_server));
+
+                ArrayList<EnforcedServer> t = new Gson().fromJson(getString(R.string.enforce_servers),
+                                                                  new TypeToken<ArrayList<EnforcedServer>>() {
+                                                                  }
+                                                                      .getType());
+
+                for (EnforcedServer e : t) {
+                    adapter.add(e.getName());
+                    servers.add(e.getUrl());
+                }
+
+                accountSetupBinding.serversSpinner.setAdapter(adapter);
+                accountSetupBinding.serversSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
+
+                    @Override
+                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                        String url = servers.get(position);
+                        
+                        if (URLUtil.isValidUrl(url)) {
+                            accountSetupBinding.hostUrlInput.setText(url);
+                            checkOcServer();
+                        }
+                    }
+
+                    @Override
+                    public void onNothingSelected(AdapterView<?> parent) {
+                        // do nothing
+                    }
+                });
+            }
         }
 
         initServerPreFragment(savedInstanceState);

+ 10 - 0
app/src/main/java/com/owncloud/android/authentication/EnforcedServer.kt

@@ -0,0 +1,10 @@
+/*
+ * Nextcloud - Android Client
+ *
+ * SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+package com.owncloud.android.authentication
+
+data class EnforcedServer(val name: String, val url: String)

+ 16 - 0
app/src/main/res/layout-land/account_setup.xml

@@ -80,6 +80,22 @@
                 </com.google.android.material.textfield.TextInputLayout>
             </FrameLayout>
 
+            <LinearLayout
+                android:id="@+id/multiple_servers_layout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone">
+
+                <Spinner
+                    android:id="@+id/servers_spinner"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:foregroundTint="#FFFFFF"
+                    android:spinnerMode="dialog"
+                    android:textColor="@color/white_helper_text" />
+            </LinearLayout>
+
             <TextView
                 android:id="@+id/host_url_input_helper_text"
                 android:layout_width="match_parent"

+ 17 - 0
app/src/main/res/layout/account_setup.xml

@@ -15,6 +15,7 @@
     android:layout_height="match_parent"
     android:layout_gravity="center"
     android:fillViewport="true"
+    android:foregroundTint="@color/login_text_color"
     android:orientation="vertical">
 
     <LinearLayout
@@ -79,6 +80,22 @@
                 </com.google.android.material.textfield.TextInputLayout>
             </FrameLayout>
 
+            <LinearLayout
+                android:id="@+id/multiple_servers_layout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone">
+
+                <Spinner
+                    android:id="@+id/servers_spinner"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:foregroundTint="#FFFFFF"
+                    android:spinnerMode="dialog"
+                    android:textColor="@color/white_helper_text" />
+            </LinearLayout>
+
             <TextView
                 android:id="@+id/host_url_input_helper_text"
                 android:layout_width="match_parent"

+ 16 - 0
app/src/main/res/layout/enforced_servers_spinner.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud - Android Client
+  ~
+  ~ SPDX-FileCopyrightText: 2006 The Android Open Source Project
+  ~ SPDX-License-Identifier: SPDX-License-Identifier: Apache-2.0
+-->
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@android:id/text1"
+    style="?android:attr/spinnerItemStyle"
+    android:singleLine="true"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:textColor="@color/login_text_color"
+    android:ellipsize="marquee"
+    android:textAlignment="inherit"/>

+ 4 - 0
app/src/main/res/values/setup.xml

@@ -123,6 +123,10 @@
     If set, will replace all other login methods available -->
     <string name="webview_login_url" translatable="false"></string>
 
+    <!--    [{\"name\":\"nameu","url":"url"},{"name":"name2","url":"url1"}]-->
+    <string name="enforce_servers" translatable="false"></string>
+
+    
     <!-- Files becomes Home -->
     <bool name="use_home">false</bool>
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1244,4 +1244,5 @@
     <string name="file_name_validator_error_forbidden_file_extensions">.%s is a forbidden file extension</string>
     <string name="file_name_validator_error_ends_with_space_period">Name ends with a space or a period</string>
     <string name="sync">Sync</string>
+    <string name="please_select_a_server">Please select a server…</string>
 </resources>