Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface AmplitudeAnalytic {
const val IS_NIGHT_MODE_ENABLED = "is_night_mode_enabled"
const val IS_AR_SUPPORTED = "is_ar_supported"
const val IS_GOOGLE_SERVICES_AVAILABLE = "is_google_services_available"
const val ACCESSIBILITY_FONT_SCALE = "accessibility_font_scale"
const val ACCESSIBILITY_SCREEN_READER_ENABLED = "accessibility_screen_reader_enabled"
}

object Launch {
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/org/stepic/droid/analytic/AnalyticImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import com.yandex.metrica.profile.UserProfile
import org.json.JSONObject
import org.stepic.droid.base.App
import org.stepic.droid.configuration.Config
import org.stepic.droid.configuration.RemoteConfig
import org.stepic.droid.di.AppSingleton
import org.stepic.droid.util.isARSupported
import org.stepic.droid.util.isScreenReaderOn
import org.stepik.android.domain.base.analytic.AnalyticEvent
import org.stepik.android.domain.base.analytic.AnalyticSource
import org.stepik.android.domain.base.analytic.UserProperty
Expand Down Expand Up @@ -66,17 +66,23 @@ constructor(
.set(AmplitudeAnalytic.Properties.PUSH_PERMISSION, if (isNotificationsEnabled) "granted" else "not_granted")
.set(AmplitudeAnalytic.Properties.IS_NIGHT_MODE_ENABLED, context.isNightModeEnabled().toString())
.set(AmplitudeAnalytic.Properties.IS_AR_SUPPORTED, context.isARSupported().toString())
.set(AmplitudeAnalytic.Properties.ACCESSIBILITY_FONT_SCALE, context.resources.configuration.fontScale.toString())
.set(AmplitudeAnalytic.Properties.ACCESSIBILITY_SCREEN_READER_ENABLED, context.isScreenReaderOn().toString())
)

updateYandexUserProfile {
apply(Attribute.notificationsEnabled().withValue(isNotificationsEnabled))
apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.IS_NIGHT_MODE_ENABLED).withValue(context.isNightModeEnabled()))
apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.IS_AR_SUPPORTED).withValue(context.isARSupported()))
apply(Attribute.customNumber(AmplitudeAnalytic.Properties.ACCESSIBILITY_FONT_SCALE).withValue(context.resources.configuration.fontScale.toDouble()))
apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.ACCESSIBILITY_SCREEN_READER_ENABLED).withValue(context.isScreenReaderOn()))
}

setFirebaseUserProperty(AmplitudeAnalytic.Properties.PUSH_PERMISSION, if (isNotificationsEnabled) "granted" else "not_granted")
setFirebaseUserProperty(AmplitudeAnalytic.Properties.IS_NIGHT_MODE_ENABLED, context.isNightModeEnabled().toString())
setFirebaseUserProperty(AmplitudeAnalytic.Properties.IS_AR_SUPPORTED, context.isARSupported().toString())
setFirebaseUserProperty(AmplitudeAnalytic.Properties.ACCESSIBILITY_FONT_SCALE, context.resources.configuration.fontScale.toString())
setFirebaseUserProperty(AmplitudeAnalytic.Properties.ACCESSIBILITY_SCREEN_READER_ENABLED, context.isScreenReaderOn().toString())
}

// Amplitude properties
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/org/stepic/droid/util/ContextExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.stepic.droid.util

import android.accessibilityservice.AccessibilityServiceInfo
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.os.Build
import android.util.TypedValue
import android.view.accessibility.AccessibilityManager
import android.widget.Toast
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources

fun Context.copyTextToClipboard(label: String? = null, textToCopy: String, toastMessage: String) {
val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
Expand Down Expand Up @@ -61,4 +58,9 @@ fun Context.isARSupported(): Boolean =
true
} catch (e : PackageManager.NameNotFoundException) {
false
}
}

fun Context.isScreenReaderOn(): Boolean {
val am = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
return am.isEnabled && am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN).isNotEmpty()
}