@@ -6,8 +6,15 @@ import android.app.Activity
66import android.app.Application
77import android.app.NotificationManager
88import android.app.role.RoleManager
9- import android.content.*
10- import android.content.pm.PackageManager
9+ import android.content.ActivityNotFoundException
10+ import android.content.ClipData
11+ import android.content.ClipboardManager
12+ import android.content.ContentResolver
13+ import android.content.ContentUris
14+ import android.content.ContentValues
15+ import android.content.Context
16+ import android.content.ContextWrapper
17+ import android.content.Intent
1118import android.content.pm.PackageManager.PERMISSION_GRANTED
1219import android.content.pm.ShortcutManager
1320import android.content.res.Configuration
@@ -17,13 +24,21 @@ import android.graphics.Point
1724import android.media.MediaMetadataRetriever
1825import android.media.RingtoneManager
1926import android.net.Uri
20- import android.os.*
27+ import android.os.Build
28+ import android.os.Bundle
29+ import android.os.Environment
30+ import android.os.Handler
31+ import android.os.Looper
2132import android.provider.BaseColumns
2233import android.provider.BlockedNumberContract.BlockedNumbers
2334import android.provider.ContactsContract.CommonDataKinds.BaseTypes
2435import android.provider.ContactsContract.CommonDataKinds.Phone
2536import android.provider.DocumentsContract
26- import android.provider.MediaStore.*
37+ import android.provider.MediaStore.Audio
38+ import android.provider.MediaStore.Files
39+ import android.provider.MediaStore.Images
40+ import android.provider.MediaStore.MediaColumns
41+ import android.provider.MediaStore.Video
2742import android.provider.OpenableColumns
2843import android.provider.Settings
2944import android.telecom.TelecomManager
@@ -45,8 +60,66 @@ import com.github.ajalt.reprint.core.Reprint
4560import com.google.gson.Gson
4661import com.google.gson.reflect.TypeToken
4762import org.fossify.commons.R
48- import org.fossify.commons.helpers.*
63+ import org.fossify.commons.helpers.AppLockManager
64+ import org.fossify.commons.helpers.BaseConfig
65+ import org.fossify.commons.helpers.ContactsHelper
66+ import org.fossify.commons.helpers.DAY_SECONDS
67+ import org.fossify.commons.helpers.FONT_SIZE_LARGE
68+ import org.fossify.commons.helpers.FONT_SIZE_MEDIUM
69+ import org.fossify.commons.helpers.FONT_SIZE_SMALL
70+ import org.fossify.commons.helpers.FRIDAY_BIT
71+ import org.fossify.commons.helpers.HOUR_SECONDS
72+ import org.fossify.commons.helpers.KEY_MAILTO
73+ import org.fossify.commons.helpers.MINUTE_SECONDS
74+ import org.fossify.commons.helpers.MONDAY_BIT
75+ import org.fossify.commons.helpers.MONTH_SECONDS
76+ import org.fossify.commons.helpers.MyContactsContentProvider
77+ import org.fossify.commons.helpers.MyContentProvider
4978import org.fossify.commons.helpers.MyContentProvider.PERMISSION_WRITE_GLOBAL_SETTINGS
79+ import org.fossify.commons.helpers.PERMISSION_ACCESS_COARSE_LOCATION
80+ import org.fossify.commons.helpers.PERMISSION_ACCESS_FINE_LOCATION
81+ import org.fossify.commons.helpers.PERMISSION_CALL_PHONE
82+ import org.fossify.commons.helpers.PERMISSION_CAMERA
83+ import org.fossify.commons.helpers.PERMISSION_GET_ACCOUNTS
84+ import org.fossify.commons.helpers.PERMISSION_MEDIA_LOCATION
85+ import org.fossify.commons.helpers.PERMISSION_POST_NOTIFICATIONS
86+ import org.fossify.commons.helpers.PERMISSION_READ_CALENDAR
87+ import org.fossify.commons.helpers.PERMISSION_READ_CALL_LOG
88+ import org.fossify.commons.helpers.PERMISSION_READ_CONTACTS
89+ import org.fossify.commons.helpers.PERMISSION_READ_MEDIA_AUDIO
90+ import org.fossify.commons.helpers.PERMISSION_READ_MEDIA_IMAGES
91+ import org.fossify.commons.helpers.PERMISSION_READ_MEDIA_VIDEO
92+ import org.fossify.commons.helpers.PERMISSION_READ_MEDIA_VISUAL_USER_SELECTED
93+ import org.fossify.commons.helpers.PERMISSION_READ_PHONE_STATE
94+ import org.fossify.commons.helpers.PERMISSION_READ_SMS
95+ import org.fossify.commons.helpers.PERMISSION_READ_STORAGE
96+ import org.fossify.commons.helpers.PERMISSION_READ_SYNC_SETTINGS
97+ import org.fossify.commons.helpers.PERMISSION_RECORD_AUDIO
98+ import org.fossify.commons.helpers.PERMISSION_SEND_SMS
99+ import org.fossify.commons.helpers.PERMISSION_WRITE_CALENDAR
100+ import org.fossify.commons.helpers.PERMISSION_WRITE_CALL_LOG
101+ import org.fossify.commons.helpers.PERMISSION_WRITE_CONTACTS
102+ import org.fossify.commons.helpers.PERMISSION_WRITE_STORAGE
103+ import org.fossify.commons.helpers.PREFS_KEY
104+ import org.fossify.commons.helpers.SATURDAY_BIT
105+ import org.fossify.commons.helpers.SUNDAY_BIT
106+ import org.fossify.commons.helpers.THURSDAY_BIT
107+ import org.fossify.commons.helpers.TIME_FORMAT_12
108+ import org.fossify.commons.helpers.TIME_FORMAT_24
109+ import org.fossify.commons.helpers.TUESDAY_BIT
110+ import org.fossify.commons.helpers.WEDNESDAY_BIT
111+ import org.fossify.commons.helpers.WEEK_SECONDS
112+ import org.fossify.commons.helpers.YEAR_SECONDS
113+ import org.fossify.commons.helpers.YOUR_ALARM_SOUNDS_MIN_ID
114+ import org.fossify.commons.helpers.ensureBackgroundThread
115+ import org.fossify.commons.helpers.isNougatPlus
116+ import org.fossify.commons.helpers.isOnMainThread
117+ import org.fossify.commons.helpers.isOreoPlus
118+ import org.fossify.commons.helpers.isQPlus
119+ import org.fossify.commons.helpers.isRPlus
120+ import org.fossify.commons.helpers.isSPlus
121+ import org.fossify.commons.helpers.isUpsideDownCakePlus
122+ import org.fossify.commons.helpers.proPackages
50123import org.fossify.commons.models.AlarmSound
51124import org.fossify.commons.models.BlockedNumber
52125import org.joda.time.DateTimeConstants
@@ -236,7 +309,7 @@ private fun isDownloadsDocument(uri: Uri) = uri.authority == "com.android.provid
236309
237310private fun isExternalStorageDocument (uri : Uri ) = uri.authority == " com.android.externalstorage.documents"
238311
239- fun Context.hasPermission (permId : Int ) = ContextCompat .checkSelfPermission(this , getPermissionString(permId)) == PackageManager . PERMISSION_GRANTED
312+ fun Context.hasPermission (permId : Int ) = ContextCompat .checkSelfPermission(this , getPermissionString(permId)) == PERMISSION_GRANTED
240313
241314fun Context.hasAllPermissions (permIds : Collection <Int >) = permIds.all(this ::hasPermission)
242315
@@ -496,31 +569,22 @@ fun Context.canAccessGlobalConfig(): Boolean {
496569 return isThankYouInstalled() && ContextCompat .checkSelfPermission(this , PERMISSION_WRITE_GLOBAL_SETTINGS ) == PERMISSION_GRANTED
497570}
498571
499- fun Context.isOrWasThankYouInstalled (): Boolean {
572+ fun Context.isOrWasThankYouInstalled (allowPretend : Boolean = true ): Boolean {
500573 return when {
501- resources.getBoolean(R .bool.pretend_thank_you_installed) -> true
502- baseConfig.hadThankYouInstalled -> true
503574 isThankYouInstalled() -> {
504- baseConfig.hadThankYouInstalled = true
575+ if (! baseConfig.hadThankYouInstalled) {
576+ baseConfig.hadThankYouInstalled = true
577+ }
505578 true
506579 }
507-
580+ baseConfig.hadThankYouInstalled -> true
581+ resources.getBoolean(R .bool.pretend_thank_you_installed) && allowPretend -> true
508582 else -> false
509583 }
510584}
511585
512586fun Context.isAProApp () = packageName.startsWith(" org.fossify." ) && packageName.removeSuffix(" .debug" ).endsWith(" .pro" )
513587
514- fun Context.getCustomizeColorsString (): String {
515- val textId = if (isOrWasThankYouInstalled()) {
516- R .string.customize_colors
517- } else {
518- R .string.customize_colors_locked
519- }
520-
521- return getString(textId)
522- }
523-
524588fun Context.addLockedLabelIfNeeded (stringId : Int ): String {
525589 return if (isOrWasThankYouInstalled()) {
526590 getString(stringId)
@@ -720,21 +784,22 @@ fun Context.storeNewYourAlarmSound(resultData: Intent): AlarmSound {
720784 return newAlarmSound
721785}
722786
723- @RequiresApi(Build .VERSION_CODES .N )
724787fun Context.saveImageRotation (path : String , degrees : Int ): Boolean {
725- if (! needsStupidWritePermissions(path)) {
788+ return if (! needsStupidWritePermissions(path)) {
726789 saveExifRotation(ExifInterface (path), degrees)
727- return true
728- } else if (isNougatPlus()) {
790+ true
791+ } else {
729792 val documentFile = getSomeDocumentFile(path)
730793 if (documentFile != null ) {
731- val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, " rw" )
794+ val parcelFileDescriptor =
795+ contentResolver.openFileDescriptor(documentFile.uri, " rw" )
732796 val fileDescriptor = parcelFileDescriptor!! .fileDescriptor
733797 saveExifRotation(ExifInterface (fileDescriptor), degrees)
734- return true
798+ true
799+ } else {
800+ false
735801 }
736802 }
737- return false
738803}
739804
740805fun Context.saveExifRotation (exif : ExifInterface , degrees : Int ) {
@@ -1298,15 +1363,21 @@ fun Context.openFullScreenIntentSettings(appId: String) {
12981363
12991364fun Context.getDayOfWeekString (dayOfWeek : Int ): String {
13001365 val dayOfWeekResId = when (dayOfWeek) {
1301- DateTimeConstants .MONDAY -> org.fossify.commons. R .string.monday
1302- DateTimeConstants .TUESDAY -> org.fossify.commons. R .string.tuesday
1303- DateTimeConstants .WEDNESDAY -> org.fossify.commons. R .string.wednesday
1304- DateTimeConstants .THURSDAY -> org.fossify.commons. R .string.thursday
1305- DateTimeConstants .FRIDAY -> org.fossify.commons. R .string.friday
1306- DateTimeConstants .SATURDAY -> org.fossify.commons. R .string.saturday
1307- DateTimeConstants .SUNDAY -> org.fossify.commons. R .string.sunday
1366+ DateTimeConstants .MONDAY -> R .string.monday
1367+ DateTimeConstants .TUESDAY -> R .string.tuesday
1368+ DateTimeConstants .WEDNESDAY -> R .string.wednesday
1369+ DateTimeConstants .THURSDAY -> R .string.thursday
1370+ DateTimeConstants .FRIDAY -> R .string.friday
1371+ DateTimeConstants .SATURDAY -> R .string.saturday
1372+ DateTimeConstants .SUNDAY -> R .string.sunday
13081373 else -> throw IllegalArgumentException (" Invalid day: $dayOfWeek " )
13091374 }
13101375
13111376 return getString(dayOfWeekResId)
13121377}
1378+
1379+ fun Context.findActivity (): Activity ? = when (this ) {
1380+ is Activity -> this
1381+ is ContextWrapper -> baseContext.findActivity()
1382+ else -> null
1383+ }
0 commit comments