소스 검색

adaptive widget for android 12+

Ethosa 3 년 전
부모
커밋
d836407e62

+ 2 - 2
.idea/deploymentTargetDropDown.xml

@@ -7,11 +7,11 @@
         <deviceKey>
           <Key>
             <type value="VIRTUAL_DEVICE_PATH" />
-            <value value="C:\Users\79833\.android\avd\Pixel_5_API_30.avd" />
+            <value value="C:\Users\79833\.android\avd\Pixel_XL_API_32.avd" />
           </Key>
         </deviceKey>
       </Target>
     </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2022-03-10T16:24:13.102251Z" />
+    <timeTargetWasSelectedWithDropDown value="2022-04-04T19:17:11.260837600Z" />
   </component>
 </project>

+ 12 - 5
app/src/main/java/com/ethosa/ktc/ui/widgets/TimetableWidget.kt

@@ -8,7 +8,7 @@ import android.content.ComponentName
 import android.content.Context
 import android.content.Intent
 import android.content.SharedPreferences
-import android.os.Bundle
+import android.os.Build
 import android.widget.RemoteViews
 import com.ethosa.ktc.R
 import com.ethosa.ktc.college.CollegeApi
@@ -47,17 +47,21 @@ class TimetableWidget : AppWidgetProvider() {
     private fun updateWidgetPendingIntent(
         context: Context?,
         appWidgetId: Int
-    ): PendingIntent? {
+    ): PendingIntent {
         val intent = Intent(context, TimetableWidget::class.java)
         val ids = AppWidgetManager.getInstance(context)
             .getAppWidgetIds(ComponentName(context!!, TimetableWidget::class.java))
         intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
         intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
+
         return PendingIntent.getBroadcast(
             context,
             appWidgetId,
             intent,
-            PendingIntent.FLAG_UPDATE_CURRENT)
+            when {
+                Build.VERSION.SDK_INT >= 31 -> PendingIntent.FLAG_MUTABLE
+                else -> PendingIntent.FLAG_UPDATE_CURRENT
+            })
     }
 
     /**
@@ -67,13 +71,16 @@ class TimetableWidget : AppWidgetProvider() {
     private fun openAppPendingIntent(
         context: Context?,
         appWidgetId: Int
-    ): PendingIntent? {
+    ): PendingIntent {
         val intent = Intent(context, MainActivity::class.java)
         return PendingIntent.getActivity(
             context,
             appWidgetId,
             intent,
-            PendingIntent.FLAG_UPDATE_CURRENT)
+            when {
+                Build.VERSION.SDK_INT >= 31 -> PendingIntent.FLAG_MUTABLE
+                else -> PendingIntent.FLAG_UPDATE_CURRENT
+            })
     }
 
     @SuppressLint("RemoteViewLayout")

+ 5 - 0
app/src/main/java/com/ethosa/ktc/utils/AppDynamicTheme.kt

@@ -0,0 +1,5 @@
+package com.ethosa.ktc.utils
+
+class AppDynamicTheme {
+
+}

+ 4 - 2
app/src/main/java/com/ethosa/ktc/utils/AppUpdater.kt

@@ -24,9 +24,11 @@ class AppUpdater(
     private val context: AppCompatActivity
 ) {
     companion object {
+        // when google services is available on phone.
         private const val GOOGLE_PLAY_MARKET_URL = "market://details?id=com.ethosa.ktc"
-        private const val GOOGLE_PLAY_WEB_URL = "https://play.google.com/store/apps/details?id=com.ethosa.ktc"
         private const val GOOGLE_PLAY_PACKAGE = "com.android.vending"
+        // When google services isn't available on phone
+        private const val GITHUB_RELEASES_URL = "https://github.com/Ethosa/KTC/releases"
 
         val VERSION = arrayOf(0, 7, 0)
         val version = "v${VERSION[0]}.${VERSION[1]}.${VERSION[2]}"
@@ -62,7 +64,7 @@ class AppUpdater(
                     intent.`package` = GOOGLE_PLAY_PACKAGE
                     context.startActivity(intent)
                 } catch (notFound: ActivityNotFoundException) {
-                    val intent = Intent(Intent.ACTION_VIEW, Uri.parse(GOOGLE_PLAY_WEB_URL))
+                    val intent = Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_RELEASES_URL))
                     context.startActivity(intent)
                 }
                 dialog.dismiss()