Setup web app, improve styling

This commit is contained in:
Maxr1998
2020-07-24 16:54:01 +02:00
parent fd7ea23c87
commit 67ec2f64e4
6 changed files with 71 additions and 9 deletions

View File

@@ -1,12 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jellyfin.android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" />
android:theme="@style/AppTheme">
<activity android:name=".WebappActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,41 @@
package org.jellyfin.android
import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import org.jellyfin.android.utils.lazyView
class WebappActivity : AppCompatActivity() {
private val webView: WebView by lazyView<WebView>(R.id.web_view)
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_webapp)
webView.webChromeClient = WebChromeClient()
webView.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
allowUniversalAccessFromFileURLs = true
}
webView.loadUrl("file:///android_asset/www/index.html")
}
override fun onBackPressed() {
val history = webView.copyBackForwardList()
if (webView.canGoBack() && history.currentIndex > 1) {
webView.goBack()
} else super.onBackPressed()
}
companion object {
init {
if (BuildConfig.DEBUG) WebView.setWebContentsDebuggingEnabled(true)
}
}
}

View File

@@ -0,0 +1,10 @@
@file:Suppress("NOTHING_TO_INLINE")
package org.jellyfin.android.utils
import android.app.Activity
import android.webkit.WebView
import androidx.annotation.IdRes
inline fun <T> Activity.lazyView(@IdRes id: Int) =
lazy(LazyThreadSafetyMode.NONE) { findViewById<WebView>(id) }

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="colorPrimary">#202020</color>
<color name="colorPrimaryDark">#1a1a1a</color>
<color name="colorAccent">#00a4dc</color>
</resources>

View File

@@ -1,10 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- Application theme -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>