mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
Merge pull request #13493 from nextcloud/enforceServers
Enforced servers
This commit is contained in:
commit
295814b953
8 changed files with 134 additions and 10 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,10 @@ 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
|
||||
if (TextUtils.isEmpty(getString(R.string.enforce_servers))) {
|
||||
initAuthorizationPreFragment(savedInstanceState);
|
||||
} else {
|
||||
showEnforcedServers();
|
||||
}
|
||||
|
||||
initServerPreFragment(savedInstanceState);
|
||||
|
@ -364,6 +373,52 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
|
||||
// webViewUtil.checkWebViewVersion();
|
||||
}
|
||||
}
|
||||
|
||||
private void showEnforcedServers() {
|
||||
|
||||
showAuthStatus();
|
||||
accountSetupBinding.hostUrlFrame.setVisibility(View.GONE);
|
||||
accountSetupBinding.hostUrlInputHelperText.setVisibility(View.GONE);
|
||||
accountSetupBinding.scanQr.setVisibility(View.GONE);
|
||||
accountSetupBinding.serversSpinner.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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final LifecycleEventObserver lifecycleEventObserver = ((lifecycleOwner, event) -> {
|
||||
if (event == Lifecycle.Event.ON_START && token != null) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <tobias.kaminsky@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.owncloud.android.authentication
|
||||
|
||||
data class EnforcedServer(val name: String, val url: String)
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Nextcloud - Android Client
|
||||
~
|
||||
~ SPDX-FileCopyrightText: 2019 Tobias Kaminsky <tobias@kaminsky.me>
|
||||
|
@ -80,6 +79,16 @@
|
|||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/servers_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:foregroundTint="#FFFFFF"
|
||||
android:spinnerMode="dialog"
|
||||
android:textColor="@color/white_helper_text"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/host_url_input_helper_text"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Nextcloud - Android Client
|
||||
~
|
||||
~ SPDX-FileCopyrightText: 2019 Tobias Kaminsky <tobias@kaminsky.me>
|
||||
|
@ -15,6 +14,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 +79,16 @@
|
|||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/servers_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:foregroundTint="#FFFFFF"
|
||||
android:spinnerMode="dialog"
|
||||
android:textColor="@color/white_helper_text"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/host_url_input_helper_text"
|
||||
android:layout_width="match_parent"
|
||||
|
|
16
app/src/main/res/layout/enforced_servers_spinner.xml
Normal file
16
app/src/main/res/layout/enforced_servers_spinner.xml
Normal file
|
@ -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: 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"/>
|
|
@ -123,6 +123,10 @@
|
|||
If set, will replace all other login methods available -->
|
||||
<string name="webview_login_url" translatable="false"></string>
|
||||
|
||||
<!-- [{\"name\":\"name1\",\"url\":\"url\"},{\"name\":\"name2\",\"url\":\"url1\"}]-->
|
||||
<string name="enforce_servers" translatable="false"></string>
|
||||
|
||||
|
||||
<!-- Files becomes Home -->
|
||||
<bool name="use_home">false</bool>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue