Skip to content

Commit

Permalink
Fixed some files to suit my needs
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Jun 30, 2022
1 parent 5a22515 commit 9abeb86
Show file tree
Hide file tree
Showing 47 changed files with 292 additions and 509 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import com.f0x1d.logfox.extensions.notificationManagerCompat
import com.google.android.material.color.DynamicColors
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.MainScope

Expand All @@ -22,6 +23,8 @@ class LogFoxApp: Application() {
super.onCreate()
instance = this

DynamicColors.applyToActivitiesIfAvailable(this)

notificationManagerCompat.apply {
val loggingStatusChannel = NotificationChannelCompat.Builder(LOGGING_STATUS_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_MIN)
.setName(getString(R.string.status))
Expand Down
59 changes: 4 additions & 55 deletions app/src/main/java/com/f0x1d/logfox/extensions/ContextExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.f0x1d.logfox.extensions

import android.Manifest
import android.app.Activity
import android.app.ActivityManager
import android.app.PendingIntent
import android.app.Service
import android.content.*
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.repository.LoggingRepository
import com.f0x1d.logfox.service.LoggingService
import com.f0x1d.logfox.utils.pendingIntentFlags
import kotlin.system.exitProcess


Expand All @@ -33,42 +31,6 @@ fun Context.hasPermissionToReadLogs() = ContextCompat.checkSelfPermission(
val Context.notificationManagerCompat get() = NotificationManagerCompat.from(this)
val Context.activityManager get() = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager

fun <T : BroadcastReceiver> Context.makeBroadcastPendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getBroadcast(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : BroadcastReceiver> Context.makeBroadcastPendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeBroadcastPendingIntent(
id,
clazz
) { putExtras(extras) }

fun <T : Service> Context.makeServicePendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getService(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : Service> Context.makeServicePendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeServicePendingIntent(
id,
clazz
) { putExtras(extras) }

fun <T : Activity> Context.makeActivityPendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getActivity(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : Activity> Context.makeActivityPendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeActivityPendingIntent(
id,
clazz
) { putExtras(extras) }

fun Context.startLoggingAndService(loggingRepository: LoggingRepository) {
loggingRepository.startLoggingIfNot()

Expand Down Expand Up @@ -104,19 +66,6 @@ fun Context.shareIntent(text: String) {
startActivity(Intent.createChooser(intent, getString(R.string.share)))
}

fun Context.isOmnibinInstalled() = try {
packageManager.getPackageInfo("com.f0x1d.dogbin", 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}

fun uploadToFoxBinIntent(content: String) = Intent("com.f0x1d.dogbin.ACTION_UPLOAD_TO_FOXBIN").apply {
putExtra(Intent.EXTRA_TEXT, content)
type = "text/plain"
}
fun Context.uploadToFoxBin(content: String) = startActivity(uploadToFoxBinIntent(content))

fun Context.catchingNotNumber(block: () -> Unit) = try {
block.invoke()
} catch (e: NumberFormatException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.f0x1d.logfox.extensions

import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

suspend fun <T> MutableLiveData<T>.suspendAndPostValue(data: T) = withContext(Dispatchers.Main.immediate) {
value = data
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/extensions/OmnibinExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.f0x1d.logfox.extensions

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager

fun Context.isOmnibinInstalled() = try {
packageManager.getPackageInfo("com.f0x1d.dogbin", 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}

fun uploadToFoxBinIntent(content: String) = Intent("com.f0x1d.dogbin.ACTION_UPLOAD_TO_FOXBIN").apply {
putExtra(Intent.EXTRA_TEXT, content)
type = "text/plain"
}
fun Context.uploadToFoxBin(content: String) = startActivity(uploadToFoxBinIntent(content))
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.f0x1d.logfox.extensions

import android.app.Activity
import android.app.PendingIntent
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.f0x1d.logfox.utils.pendingIntentFlags

fun <T : BroadcastReceiver> Context.makeBroadcastPendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getBroadcast(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : BroadcastReceiver> Context.makeBroadcastPendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeBroadcastPendingIntent(
id,
clazz
) { putExtras(extras) }

fun <T : Service> Context.makeServicePendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getService(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : Service> Context.makeServicePendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeServicePendingIntent(
id,
clazz
) { putExtras(extras) }

fun <T : Activity> Context.makeActivityPendingIntent(id: Int, clazz: Class<T>, setup: Intent.() -> Unit) = PendingIntent.getActivity(
this,
id,
Intent(this, clazz).also { setup.invoke(it) },
pendingIntentFlags
)

fun <T : Activity> Context.makeActivityPendingIntent(id: Int, clazz: Class<T>, extras: Bundle = Bundle.EMPTY) = makeActivityPendingIntent(
id,
clazz
) { putExtras(extras) }
20 changes: 20 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/ui/view/OpenSansToolbar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.f0x1d.logfox.ui.view

import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.children
import com.f0x1d.logfox.R
import com.google.android.material.appbar.MaterialToolbar

class OpenSansToolbar(context: Context, attributeSet: AttributeSet) : MaterialToolbar(context, attributeSet) {

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)

children.forEach {
if (it is TextView) it.typeface = ResourcesCompat.getFont(context, R.font.google_sans_medium)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.viewModelScope
import com.f0x1d.logfox.extensions.suspendAndPostValue
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
Expand All @@ -27,15 +28,15 @@ abstract class BaseFlowProxyViewModel<T, R>(application: Application, private va
stopCollector()

startCollector {
data.postValue(it)
data.suspendAndPostValue(it)
}
}

protected fun collectOneValue() {
stopCollector()

startCollector {
data.postValue(it)
data.suspendAndPostValue(it)
stopCollector()
}
}
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

Loading

0 comments on commit 9abeb86

Please sign in to comment.