Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Merge branch 'kik-btaski/main'
Browse files Browse the repository at this point in the history
Bnyro committed Feb 21, 2024
2 parents 22fd464 + 554dea6 commit 9e961f3
Showing 4 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import com.bnyro.recorder.enums.RecorderType
import com.bnyro.recorder.ui.MainActivity

@RequiresApi(Build.VERSION_CODES.N)
@@ -12,7 +13,7 @@ class AudioRecorderTile : TileService() {
super.onClick()

val intent = Intent(this, MainActivity::class.java)
.putExtra("action", "audio")
.putExtra(MainActivity.EXTRA_ACTION_KEY, RecorderType.AUDIO.name)
.apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import com.bnyro.recorder.enums.RecorderType
import com.bnyro.recorder.ui.MainActivity

@RequiresApi(Build.VERSION_CODES.N)
@@ -12,7 +13,7 @@ class ScreenRecorderTile : TileService() {
super.onClick()

val intent = Intent(this, MainActivity::class.java)
.putExtra("action", "screen")
.putExtra(MainActivity.EXTRA_ACTION_KEY, RecorderType.VIDEO.name)
.apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
33 changes: 27 additions & 6 deletions app/src/main/java/com/bnyro/recorder/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -16,16 +16,17 @@ import com.bnyro.recorder.ui.models.ThemeModel
import com.bnyro.recorder.ui.theme.RecordYouTheme

class MainActivity : ComponentActivity() {
private var initialRecorder = RecorderType.NONE
private var exitAfterRecordingStart = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val themeModel: ThemeModel by viewModels()

val initialRecorder = when (intent?.getStringExtra("action")) {
"audio" -> RecorderType.AUDIO
"screen" -> RecorderType.VIDEO
else -> RecorderType.NONE
}
initialRecorder = intent?.getStringExtra(EXTRA_ACTION_KEY)?.let {
RecorderType.valueOf(it)
} ?: RecorderType.NONE
intent?.putExtra(EXTRA_ACTION_KEY, "")

setContent {
RecordYouTheme(
@@ -51,4 +52,24 @@ class MainActivity : ComponentActivity() {
}
}
}

override fun onPause() {
super.onPause()
if (initialRecorder != RecorderType.NONE) {
exitAfterRecordingStart = true
initialRecorder = RecorderType.NONE
}
}

override fun onResume() {
super.onResume()
if (exitAfterRecordingStart) {
exitAfterRecordingStart = false
finish()
}
}

companion object {
const val EXTRA_ACTION_KEY = "action"
}
}
7 changes: 4 additions & 3 deletions app/src/main/java/com/bnyro/recorder/util/ShortcutHelper.kt
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import com.bnyro.recorder.R
import com.bnyro.recorder.enums.RecorderType
import com.bnyro.recorder.ui.MainActivity

object ShortcutHelper {
@@ -16,8 +17,8 @@ object ShortcutHelper {
@DrawableRes val iconRes: Int,
@StringRes val label: Int
) {
object RecordAudio : AppShortcut("audio", R.drawable.ic_audio, R.string.record_sound)
object RecordScreen : AppShortcut("screen", R.drawable.ic_screen, R.string.record_screen)
object RecordAudio : AppShortcut(RecorderType.AUDIO.name, R.drawable.ic_audio, R.string.record_sound)
object RecordScreen : AppShortcut(RecorderType.VIDEO.name, R.drawable.ic_screen, R.string.record_screen)
}
private val shortcuts = listOf(AppShortcut.RecordAudio, AppShortcut.RecordScreen)

@@ -29,7 +30,7 @@ object ShortcutHelper {
.setIntent(
Intent(context, MainActivity::class.java).apply {
this.action = Intent.ACTION_VIEW
putExtra("action", action)
putExtra(MainActivity.EXTRA_ACTION_KEY, action)
}
)
.build()

0 comments on commit 9e961f3

Please sign in to comment.