Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Jul 28, 2022
1 parent a7a14bb commit 83158dd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")

implementation("androidx.core:core-ktx:1.8.0")
implementation("androidx.activity:activity-ktx:1.5.0")
implementation("androidx.fragment:fragment-ktx:1.5.0")
implementation("androidx.appcompat:appcompat:1.4.2")
implementation("androidx.activity:activity-ktx:1.5.1")
implementation("androidx.fragment:fragment-ktx:1.5.1")
implementation("androidx.appcompat:appcompat:1.5.0-rc01")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("com.google.android.material:material:1.6.1")
implementation("androidx.window:window:1.0.0")

implementation("androidx.navigation:navigation-fragment-ktx:2.5.0")
implementation("androidx.navigation:navigation-ui-ktx:2.5.0")
implementation("androidx.lifecycle:lifecycle-livedata:2.5.0")
implementation("androidx.lifecycle:lifecycle-common:2.5.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.1")
implementation("androidx.navigation:navigation-ui-ktx:2.5.1")
implementation("androidx.lifecycle:lifecycle-livedata:2.5.1")
implementation("androidx.lifecycle:lifecycle-common:2.5.1")

implementation("com.afollestad.material-dialogs:core:3.3.0")
implementation("com.afollestad.material-dialogs:color:3.3.0")
Expand All @@ -125,7 +125,7 @@ dependencies {
exclude group: "com.android.support"
}
firebaseImplementation("com.google.firebase:firebase-analytics:21.1.0")
firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.11")
firebaseImplementation("com.google.firebase:firebase-crashlytics:18.2.12")
firebaseImplementation("com.google.android.gms:play-services-ads:21.1.0")

// debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ abstract class AdFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLay
else adViewContainer.viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this)

var adWidthPixels = adViewContainer.width.toFloat()
if (adWidthPixels == 0f) adWidthPixels = WindowMetricsCalculator.getOrCreate()
.computeCurrentWindowMetrics(requireActivity()).bounds.width().toFloat()
activity?.let {
if (adWidthPixels == 0f) adWidthPixels = WindowMetricsCalculator.getOrCreate()
.computeCurrentWindowMetrics(it).bounds.width().toFloat()
} ?: return // Not attached to an activity.

val adWidth = (adWidthPixels / resources.displayMetrics.density).toInt()
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(requireContext(), adWidth)

adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this)
loadAd(adViewContainer)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package info.dvkr.screenstream.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import com.elvishew.xlog.XLog
import info.dvkr.screenstream.data.other.getLog
import info.dvkr.screenstream.data.settings.SettingsReadOnly
Expand All @@ -18,15 +19,20 @@ class BootReceiver : BroadcastReceiver(), KoinComponent {
private val settingsReadOnly: SettingsReadOnly by inject()

override fun onReceive(context: Context, intent: Intent) {
XLog.d(getLog("onReceive", "Invoked"))
XLog.d(getLog("onReceive", "Invoked: (SDK: ${Build.VERSION.SDK_INT}) Intent Action: ${intent.action}"))

if (runBlocking { settingsReadOnly.startOnBootFlow.first().not() }) Runtime.getRuntime().exit(0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (intent.action != Intent.ACTION_BOOT_COMPLETED) {
Runtime.getRuntime().exit(0)
return
}
}

if (
intent.action == "android.intent.action.BOOT_COMPLETED" ||
intent.action == "android.intent.action.QUICKBOOT_POWERON"
) {
IntentAction.StartOnBoot.sendToAppService(context)
if (runBlocking { settingsReadOnly.startOnBootFlow.first().not() }) {
Runtime.getRuntime().exit(0)
return
}

IntentAction.StartOnBoot.sendToAppService(context)
}
}
12 changes: 8 additions & 4 deletions app/src/main/kotlin/info/dvkr/screenstream/service/AppService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.koin.android.ext.android.inject
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
Expand All @@ -49,9 +47,15 @@ class AppService : Service() {

fun getAppServiceIntent(context: Context): Intent = Intent(context.applicationContext, AppService::class.java)

fun startService(context: Context, intent: Intent) = context.startService(intent)
fun startService(context: Context, intent: Intent) {
runCatching { context.startService(intent) }
.onFailure { XLog.e(getLog("startService", "Failed to start Service"), it) }
}

fun startForeground(context: Context, intent: Intent) = ContextCompat.startForegroundService(context, intent)
fun startForeground(context: Context, intent: Intent) {
runCatching { ContextCompat.startForegroundService(context, intent) }
.onFailure { XLog.e(getLog("startForeground", "Failed to start Foreground Service"), it) }
}
}

class AppServiceBinder(private val serviceMessageSharedFlow: MutableSharedFlow<ServiceMessage>) : Binder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TileActionService : TileService() {
isBound = false
}
}
bindService(AppService.getAppServiceIntent(this), serviceConnection!!, Context.BIND_AUTO_CREATE)
serviceConnection?.let { bindService(AppService.getAppServiceIntent(this), it, Context.BIND_AUTO_CREATE) }
} else {
isStreaming = false
updateTile()
Expand All @@ -80,6 +80,7 @@ class TileActionService : TileService() {
coroutineScope?.cancel()
coroutineScope = null
serviceConnection?.let { unbindService(it) }
serviceConnection = null
isBound = false
}
isStreaming = false
Expand Down

0 comments on commit 83158dd

Please sign in to comment.