Skip to content

Commit

Permalink
Merge pull request #49 from twin-te/migrate-target-api-level-to-34
Browse files Browse the repository at this point in the history
Bump up target API Level to 34
  • Loading branch information
private-yusuke authored Apr 18, 2024
2 parents 6620b13 + 3dcb6be commit 3f3ca0a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@
<service
android:name=".widget.V3MediumWidgetRemoteViewService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />
android:permission="android.permission.BIND_REMOTEVIEWS"
android:foregroundServiceType="dataSync" />
<!-- 大ウィジットのデータ供給用Service -->
<service
android:name=".widget.V3LargeWidgetRemoteViewService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />
android:permission="android.permission.BIND_REMOTEVIEWS"
android:foregroundServiceType="dataSync" />

<!-- ウィジット関連終わり -->

Expand Down
52 changes: 34 additions & 18 deletions app/src/main/java/net/twinte/android/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package net.twinte.android

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.res.Configuration
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
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
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
Expand Down Expand Up @@ -106,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")
Expand Down Expand Up @@ -159,24 +190,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 {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<WebView
android:id="@+id/main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:theme="@style/Theme.AppCompat.DayNight" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@
<string name="widget_medium_label">中ウィジット</string>
<string name="widget_large_label">大ウィジット</string>
<string name="google_server_client_id" tools:ignore="TypographyDashes">617914047709-9dgo7djtadc11tf1tlrh8fj70v3glahe.apps.googleusercontent.com</string>
<string name="snackbar_notification_not_granted_text">通知を許可して振替日程の通知を受け取る</string>
<string name="snackbar_notification_not_granted_settings">設定</string>
</resources>

0 comments on commit 3f3ca0a

Please sign in to comment.