From 1c3c858d326307869ec05b289dfc4eed79b3073f Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Mon, 24 Aug 2020 20:05:47 +0200 Subject: [PATCH 1/2] Split up web app and connection handling Extract connection handling into extra class, don't reset server URL on errors, replace toasts with error text. --- .../org/jellyfin/mobile/WebappActivity.kt | 120 ++-------- .../mobile/utils/ServerConnectionUtils.kt | 80 ------- .../mobile/webapp/ConnectionHelper.kt | 207 ++++++++++++++++++ app/src/main/res/layout/connect_server.xml | 21 +- app/src/main/res/values-b+es+419/strings.xml | 4 +- app/src/main/res/values-cs/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-es-rAR/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 4 +- app/src/main/res/values-fi/strings.xml | 4 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-hu/strings.xml | 4 +- app/src/main/res/values-id/strings.xml | 4 +- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ko/strings.xml | 4 +- app/src/main/res/values-nb-rNO/strings.xml | 4 +- app/src/main/res/values-nl/strings.xml | 4 +- app/src/main/res/values-ro/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sk/strings.xml | 4 +- app/src/main/res/values-sl/strings.xml | 4 +- app/src/main/res/values-ta/strings.xml | 4 +- app/src/main/res/values-uk/strings.xml | 4 +- app/src/main/res/values-zh-rCN/strings.xml | 4 +- app/src/main/res/values/colors.xml | 3 +- app/src/main/res/values/strings.xml | 7 +- 26 files changed, 284 insertions(+), 234 deletions(-) delete mode 100644 app/src/main/java/org/jellyfin/mobile/utils/ServerConnectionUtils.kt create mode 100644 app/src/main/java/org/jellyfin/mobile/webapp/ConnectionHelper.kt diff --git a/app/src/main/java/org/jellyfin/mobile/WebappActivity.kt b/app/src/main/java/org/jellyfin/mobile/WebappActivity.kt index 7f8babf8..4cbdf6ce 100644 --- a/app/src/main/java/org/jellyfin/mobile/WebappActivity.kt +++ b/app/src/main/java/org/jellyfin/mobile/WebappActivity.kt @@ -7,24 +7,10 @@ import android.content.Intent import android.content.ServiceConnection import android.os.Bundle import android.os.IBinder -import android.view.KeyEvent -import android.view.View -import android.view.inputmethod.EditorInfo -import android.view.inputmethod.InputMethodManager import android.webkit.* -import android.widget.Button -import android.widget.EditText import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat -import androidx.core.content.getSystemService -import androidx.core.view.doOnNextLayout -import androidx.core.view.isVisible -import androidx.core.view.postDelayed -import androidx.lifecycle.lifecycleScope -import kotlinx.coroutines.launch -import okhttp3.HttpUrl -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import org.jellyfin.mobile.bridge.Commands.triggerInputManagerAction import org.jellyfin.mobile.bridge.NativeInterface @@ -32,6 +18,7 @@ import org.jellyfin.mobile.bridge.NativePlayer import org.jellyfin.mobile.cast.Chromecast import org.jellyfin.mobile.utils.* import org.jellyfin.mobile.utils.Constants.INPUT_MANAGER_COMMAND_BACK +import org.jellyfin.mobile.webapp.ConnectionHelper import timber.log.Timber import java.io.Reader @@ -40,6 +27,10 @@ class WebappActivity : AppCompatActivity(), WebViewController { val appPreferences: AppPreferences by lazy { AppPreferences(this) } val httpClient = OkHttpClient() val chromecast = Chromecast() + private val connectionHelper = ConnectionHelper(this) + + val rootView: FrameLayout by lazyView(R.id.root_view) + val webView: WebView by lazyView(R.id.web_view) var serviceBinder: RemotePlayerService.ServiceBinder? = null private set @@ -54,15 +45,6 @@ class WebappActivity : AppCompatActivity(), WebViewController { } } - private var cachedInstanceUrl: HttpUrl? = null - private var connected = false - - private val rootView: FrameLayout by lazyView(R.id.root_view) - private val webView: WebView by lazyView(R.id.web_view) - private val serverSetupLayout: View by lazy { layoutInflater.inflate(R.layout.connect_server, rootView, false) } - private val hostInput: EditText by lazy { serverSetupLayout.findViewById(R.id.host_input) } - private val connectButton: Button by lazy { serverSetupLayout.findViewById