From 3652bc948e260edc43f6bab24694e12949bf37a0 Mon Sep 17 00:00:00 2001
From: private-yusuke <30387586+private-yusuke@users.noreply.github.com>
Date: Thu, 18 Apr 2024 15:11:48 +0900
Subject: [PATCH 1/3] Sync dark mode ability with the device in the most
preferred way as of API level 34
see: https://developer.android.com/about/versions/13/behavior-changes-13#webview-color-theme
---
.../java/net/twinte/android/MainActivity.kt | 20 ++-----------------
app/src/main/res/layout/activity_main.xml | 3 ++-
2 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/app/src/main/java/net/twinte/android/MainActivity.kt b/app/src/main/java/net/twinte/android/MainActivity.kt
index 01be25c..aaa5290 100644
--- a/app/src/main/java/net/twinte/android/MainActivity.kt
+++ b/app/src/main/java/net/twinte/android/MainActivity.kt
@@ -2,7 +2,6 @@ package net.twinte.android
import android.annotation.SuppressLint
import android.content.Intent
-import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.webkit.CookieManager
@@ -159,24 +158,9 @@ class MainActivity : AppCompatActivity(), SubWebViewFragment.Callback {
}
if (
- WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK) &&
- WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)
+ WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)
) {
- when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
- // ダークモードサポートだったら
- Configuration.UI_MODE_NIGHT_YES -> {
- // ダークモード有効
- WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON)
- // ダークモードのスタイリングはページが行う
- WebSettingsCompat.setForceDarkStrategy(
- settings,
- WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY,
- )
- }
- Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
- WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF)
- }
- }
+ WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, true)
}
addJavascriptInterface(
object {
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 9917dc1..716c9b8 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -10,6 +10,7 @@
+ android:layout_height="match_parent"
+ android:theme="@style/Theme.AppCompat.DayNight" />
From bc96db828b9f837f0e34ef17368d3994af485af2 Mon Sep 17 00:00:00 2001
From: private-yusuke <30387586+private-yusuke@users.noreply.github.com>
Date: Thu, 18 Apr 2024 15:40:17 +0900
Subject: [PATCH 2/3] Ask for the permission to send notifications for devices
with API Level >= 33
---
.../java/net/twinte/android/MainActivity.kt | 32 +++++++++++++++++++
app/src/main/res/values/strings.xml | 2 ++
2 files changed, 34 insertions(+)
diff --git a/app/src/main/java/net/twinte/android/MainActivity.kt b/app/src/main/java/net/twinte/android/MainActivity.kt
index aaa5290..bfbbacd 100644
--- a/app/src/main/java/net/twinte/android/MainActivity.kt
+++ b/app/src/main/java/net/twinte/android/MainActivity.kt
@@ -1,9 +1,13 @@
package net.twinte.android
+import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
+import android.content.pm.PackageManager
import android.net.Uri
+import android.os.Build
import android.os.Bundle
+import android.provider.Settings
import android.webkit.CookieManager
import android.webkit.JavascriptInterface
import android.webkit.ValueCallback
@@ -11,7 +15,9 @@ import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.widget.Toast
+import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
+import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewClientCompat
@@ -19,6 +25,7 @@ import androidx.webkit.WebViewFeature
import androidx.work.WorkManager
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
+import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@@ -105,6 +112,31 @@ class MainActivity : AppCompatActivity(), SubWebViewFragment.Callback {
?: twinteUrlBuilder(serverSettings).buildUrl()
binding.mainWebview.loadUrl(url)
+
+ if (ActivityCompat.checkSelfPermission(
+ this,
+ Manifest.permission.POST_NOTIFICATIONS,
+ ) != PackageManager.PERMISSION_GRANTED
+ ) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
+ if (!isGranted) {
+ Snackbar.make(
+ binding.root,
+ getString(R.string.snackbar_notification_not_granted_text),
+ Snackbar.LENGTH_LONG,
+ ).setAction(getString(R.string.snackbar_notification_not_granted_settings)) {
+ startActivity(
+ Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(Settings.EXTRA_APP_PACKAGE, packageName),
+ )
+ }.show()
+ }
+ }.launch(Manifest.permission.POST_NOTIFICATIONS)
+ }
+ return
+ }
}
@SuppressLint("SetJavaScriptEnabled")
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 78cf3dd..1995aed 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -43,4 +43,6 @@
中ウィジット
大ウィジット
617914047709-9dgo7djtadc11tf1tlrh8fj70v3glahe.apps.googleusercontent.com
+ 通知を許可して振替日程の通知を受け取る
+ 設定
From 3dcb6be91c075c1f459307ae2a6f7f232cbf3dc4 Mon Sep 17 00:00:00 2001
From: private-yusuke <30387586+private-yusuke@users.noreply.github.com>
Date: Thu, 18 Apr 2024 15:50:50 +0900
Subject: [PATCH 3/3] Bump up targetSdk to 34
---
app/build.gradle.kts | 4 ++--
app/src/main/AndroidManifest.xml | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 5a8058c..ae0dd66 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -7,12 +7,12 @@ plugins {
}
android {
- compileSdkVersion(33)
+ compileSdk = 34
defaultConfig {
applicationId = "net.twinte.android"
minSdk = 24
- targetSdkVersion (31)
+ targetSdk = 34
versionCode = 19
versionName = "2.0.3"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7404171..409c694 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -82,12 +82,14 @@
+ android:permission="android.permission.BIND_REMOTEVIEWS"
+ android:foregroundServiceType="dataSync" />
+ android:permission="android.permission.BIND_REMOTEVIEWS"
+ android:foregroundServiceType="dataSync" />