Skip to content
Closed
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
10 changes: 10 additions & 0 deletions app/src/main/java/com/papi/nova/PcView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,16 @@ class PcView : AppCompatActivity(), AdapterFragmentCallbacks {
}

initializeViews(prefs)
handleWelcomeAction(intent.getStringExtra(NovaWelcomeActivity.EXTRA_WELCOME_ACTION))
}

private fun handleWelcomeAction(action: String?) {
if (action != NovaWelcomeActivity.ACTION_SCAN_QR) {
return
}

intent.removeExtra(NovaWelcomeActivity.EXTRA_WELCOME_ACTION)
window.decorView.post { launchQrScanner() }
}

private fun startComputerUpdates() {
Expand Down
47 changes: 34 additions & 13 deletions app/src/main/java/com/papi/nova/ui/NovaWelcomeActivity.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.papi.nova.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.papi.nova.R
import com.papi.nova.PcView
import com.papi.nova.R
import com.papi.nova.preferences.AddComputerManually

/**
* First-launch welcome screen. Shows once, then never again.
Expand All @@ -15,22 +19,39 @@ class NovaWelcomeActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_nova_welcome)

findViewById<android.view.View>(R.id.welcome_start_btn).setOnClickListener {
// Mark as seen
getSharedPreferences("nova_prefs", MODE_PRIVATE).edit()
.putBoolean("welcome_seen", true)
.commit()
val next = android.content.Intent(this, PcView::class.java)
intent.extras?.let { next.putExtras(it) }
startActivity(next)
finish()
findViewById<View>(R.id.welcome_discover_btn).setOnClickListener {
finishWelcome(Intent(this, PcView::class.java))
}
findViewById<View>(R.id.welcome_add_manual_btn).setOnClickListener {
finishWelcome(Intent(this, AddComputerManually::class.java))
}
findViewById<View>(R.id.welcome_scan_qr_btn).setOnClickListener {
finishWelcome(
Intent(this, PcView::class.java)
.putExtra(EXTRA_WELCOME_ACTION, ACTION_SCAN_QR),
)
}
}

private fun finishWelcome(next: Intent) {
getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit()
.putBoolean(KEY_WELCOME_SEEN, true)
.commit()
intent.extras?.let { next.putExtras(it) }
next.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(next)
finish()
}

companion object {
fun shouldShow(context: android.content.Context): Boolean {
return !context.getSharedPreferences("nova_prefs", android.content.Context.MODE_PRIVATE)
.getBoolean("welcome_seen", false)
const val EXTRA_WELCOME_ACTION = "com.papi.nova.extra.WELCOME_ACTION"
const val ACTION_SCAN_QR = "scan_qr"
private const val PREFS_NAME = "nova_prefs"
private const val KEY_WELCOME_SEEN = "welcome_seen"

fun shouldShow(context: Context): Boolean {
return !context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
.getBoolean(KEY_WELCOME_SEEN, false)
}
}
}
Loading
Loading