Introduce PassScanActivity

Hope to fix #244 - nicer anyway - less dialogs is better
This commit is contained in:
ligi 2020-03-01 00:38:32 +01:00
parent b98155e48b
commit 2831f60c30
No known key found for this signature in database
GPG key ID: 8E81894010ABF23D
15 changed files with 109 additions and 71 deletions

View file

@ -1804,6 +1804,7 @@
<activity
android:name=".ui.FullscreenBarcodeActivity"
android:label="@string/app_name"/>
<activity android:name=".ui.PassScanActivity" />
</application>

View file

@ -3,9 +3,7 @@ package org.ligi.passandroid.ui
import android.Manifest
import android.annotation.TargetApi
import android.app.Activity
import android.app.ProgressDialog
import android.content.ActivityNotFoundException
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
@ -22,13 +20,10 @@ import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.pass_list.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.ligi.kaxt.setButton
import org.ligi.kaxt.startActivityFromClass
import org.ligi.kaxt.startActivityFromURL
import org.ligi.passandroid.R
import org.ligi.passandroid.events.PassStoreChangeEvent
import org.ligi.passandroid.events.ScanFinishedEvent
import org.ligi.passandroid.events.ScanProgressEvent
import org.ligi.passandroid.functions.createAndAddEmptyPass
import org.ligi.passandroid.model.PassStoreProjection
import org.ligi.passandroid.model.State
@ -51,25 +46,7 @@ class PassListActivity : PassAndroidActivity() {
private val drawerToggle by lazy { ActionBarDrawerToggle(this, drawer_layout, R.string.drawer_open, R.string.drawer_close) }
private val adapter by lazy { PassTopicFragmentPagerAdapter(passStore.classifier, supportFragmentManager) }
private val pd by lazy { ProgressDialog(this) }
@Subscribe(threadMode = ThreadMode.MAIN)
fun onScanProgress(event: ScanProgressEvent) {
if (pd.isShowing) {
pd.setMessage(event.message)
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onScanFinished(event: ScanFinishedEvent) {
if (pd.isShowing) {
val message = getString(R.string.scan_finished_dialog_text, event.foundPasses.size)
pd.dismiss()
AlertDialog.Builder(this@PassListActivity).setTitle(R.string.scan_finished_dialog_title).setMessage(message).setPositiveButton(android.R.string.ok, null).show()
}
}
@TargetApi(16)
@OnPermissionDenied(Manifest.permission.READ_EXTERNAL_STORAGE)
@ -80,22 +57,7 @@ class PassListActivity : PassAndroidActivity() {
@TargetApi(16)
@NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
fun scan() {
val intent = Intent(this, SearchPassesIntentService::class.java)
startService(intent)
pd.setTitle(R.string.scan_progressdialog_title)
pd.setMessage(getString(R.string.scan_progressdialog_message))
pd.setCancelable(false)
pd.isIndeterminate = true
pd.setButton(DialogInterface.BUTTON_NEUTRAL, R.string.scan_dialog_send_background_button) {
this@PassListActivity.finish()
}
pd.setButton(DialogInterface.BUTTON_POSITIVE, android.R.string.cancel) {
stopService(intent)
}
pd.show()
}
fun scan() = startActivity(Intent(this, PassScanActivity::class.java))
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
@ -227,7 +189,7 @@ class PassListActivity : PassAndroidActivity() {
for (pass in passStoreProjection.passList) {
passStore.deletePassWithId(pass.id)
}
}.setNegativeButton(android.R.string.cancel, null).show()
}.setNegativeButton(android.R.string.cancel, null).show()
true
}
else -> drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item)

View file

@ -0,0 +1,67 @@
package org.ligi.passandroid.ui
import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View.GONE
import kotlinx.android.synthetic.main.activity_scan.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.ligi.passandroid.R
import org.ligi.passandroid.events.ScanFinishedEvent
import org.ligi.passandroid.events.ScanProgressEvent
class PassScanActivity : PassAndroidActivity() {
@Subscribe(threadMode = ThreadMode.MAIN)
fun onScanProgress(event: ScanProgressEvent) {
progress_text.text = event.message
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onScanFinished(event: ScanFinishedEvent) {
progress_container.visibility = GONE
val message = getString(R.string.scan_finished_dialog_text, event.foundPasses.size)
AlertDialog.Builder(this)
.setTitle(R.string.scan_finished_dialog_title)
.setMessage(message)
.setPositiveButton(android.R.string.ok) { _, _ ->
finish()
}
.show()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scan)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val intent = Intent(this, SearchPassesIntentService::class.java)
startService(intent)
}
override fun onResume() {
super.onResume()
bus.register(this)
}
override fun onPause() {
bus.unregister(this)
super.onPause()
}
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}

View file

@ -103,7 +103,6 @@ class SearchPassesIntentService : IntentService("SearchPassesIntentService") {
* recursive voyage starting at path to find files named .pkpass
*/
private fun searchIn(path: File, recursive: Boolean) {
if (System.currentTimeMillis() - lastProgressUpdate > 1000) {
lastProgressUpdate = System.currentTimeMillis()
val msg = path.toString()

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/progress_container"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/progress"
android:layout_gravity="center"
android:text="@string/scan_pass_message"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/progress"
android:layout_gravity="center"
android:id="@+id/progress_text"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>

View file

@ -119,9 +119,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">Und %d mehr</string>
<string name="scan_finished_dialog_title">Suche abgeschlossen</string>
<string name="scan_finished_dialog_text">%d Pässe gefunden</string>
<string name="scan_progressdialog_title">Suche…</string>
<string name="scan_progressdialog_message">Bitte warten</string>
<string name="scan_dialog_send_background_button">Hintergrund</string>
<string name="emtytrash_label">Leere Papierkorb</string>
<string name="barcode_edit_hint_alternative_message">Alternative Nachricht</string>
<string name="barcode_edit_random">Zufällig</string>

View file

@ -114,9 +114,6 @@ ESTE SOFTWARE SE OFRECE \"TAL CUAL\" Y CUALQUIER GARANTÍA EXPRESA O IMPLÍCITA,
<string name="found__pass">Y %d más</string>
<string name="scan_finished_dialog_title">Búsqueda terminada</string>
<string name="scan_finished_dialog_text">encontrados %d Passbooks</string>
<string name="scan_progressdialog_title">Buscando…</string>
<string name="scan_progressdialog_message">Por favor, espere</string>
<string name="scan_dialog_send_background_button">fondo</string>
<string name="emtytrash_label">Vaciar papelera</string>
<string name="barcode_edit_hint_alternative_message">mensaje alternativo</string>
<string name="barcode_edit_random">aleatorio</string>

View file

@ -65,9 +65,6 @@
<string name="found__pass">Eta %d gehiago</string>
<string name="scan_finished_dialog_title">Eskaneatzen amaitu da.</string>
<string name="scan_finished_dialog_text">%d pase aurkitu dira</string>
<string name="scan_progressdialog_title">Bilatzen…</string>
<string name="scan_progressdialog_message">Mesedez itxaron.</string>
<string name="scan_dialog_send_background_button">atzealdea</string>
<string name="emtytrash_label">hustu zakarrontzia</string>
<string name="barcode_edit_hint_alternative_message">Mezu alternatiboa</string>
<string name="barcode_edit_random">ausazkoa</string>

View file

@ -112,9 +112,6 @@ THIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLU
<string name="found__pass">Et %d plus</string>
<string name="scan_finished_dialog_title">Recherche terminée</string>
<string name="scan_finished_dialog_text">%d passes trouvés</string>
<string name="scan_progressdialog_title">Recherche…</string>
<string name="scan_progressdialog_message">Veuillez patienter.</string>
<string name="scan_dialog_send_background_button">arrière-plan</string>
<string name="emtytrash_label">corbeille vide</string>
<string name="barcode_edit_hint_alternative_message">message alternatif</string>
<string name="barcode_edit_random">aléatoire</string>

View file

@ -117,9 +117,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">e %d máis</string>
<string name="scan_finished_dialog_title">Busca finalizada.</string>
<string name="scan_finished_dialog_text">atopou %d passes</string>
<string name="scan_progressdialog_title">Buscando…</string>
<string name="scan_progressdialog_message">Por favor agarde.</string>
<string name="scan_dialog_send_background_button">fondo</string>
<string name="emtytrash_label">lixo baldeiro</string>
<string name="barcode_edit_hint_alternative_message">Mensaxe alternativa</string>
<string name="barcode_edit_random">ao chou</string>

View file

@ -107,9 +107,6 @@ IL SOFTWARE VIENE FORNITO \"COSÌ COM\'È\", SENZA GARANZIE, ESPRESSE O IMPLICIT
<string name="found__pass">E altri %d</string>
<string name="scan_finished_dialog_title">Scansione finita.</string>
<string name="scan_finished_dialog_text">trovato %d Pass</string>
<string name="scan_progressdialog_title">Sto cercando…</string>
<string name="scan_progressdialog_message">Aspetta.</string>
<string name="scan_dialog_send_background_button">background</string>
<string name="emtytrash_label">svuota cestino</string>
<string name="barcode_edit_hint_alternative_message">Messaggio alternativo</string>
<string name="barcode_edit_random">casuale</string>

View file

@ -122,9 +122,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">および %d 以上</string>
<string name="scan_finished_dialog_title">スキャンが終了しました。</string>
<string name="scan_finished_dialog_text">%d チケットが見つかりました</string>
<string name="scan_progressdialog_title">検索中…</string>
<string name="scan_progressdialog_message">しばらくお待ちください。</string>
<string name="scan_dialog_send_background_button">バックグラウンド</string>
<string name="emtytrash_label">ゴミ箱を空にする</string>
<string name="barcode_edit_hint_alternative_message">代りのメッセージ</string>
<string name="barcode_edit_random">ランダム</string>

View file

@ -128,9 +128,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">En %d meer</string>
<string name="scan_finished_dialog_title">Zoekactie afgewerkt.</string>
<string name="scan_finished_dialog_text">%d passen gevonden</string>
<string name="scan_progressdialog_title">Zoeken…</string>
<string name="scan_progressdialog_message">Even geduld.</string>
<string name="scan_dialog_send_background_button">achtergrond</string>
<string name="emtytrash_label">Prullenbak leegmaken</string>
<string name="barcode_edit_hint_alternative_message">alternatieve boodschap</string>
<string name="barcode_edit_random">willekeurig</string>

View file

@ -110,9 +110,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">Еще %d</string>
<string name="scan_finished_dialog_title">Поиск завершен.</string>
<string name="scan_finished_dialog_text">найдено %d карточек</string>
<string name="scan_progressdialog_title">Поиск…</string>
<string name="scan_progressdialog_message">Пожалуйста подождите.</string>
<string name="scan_dialog_send_background_button">в фоне</string>
<string name="emtytrash_label">очистить корзину</string>
<string name="barcode_edit_hint_alternative_message">альтернативное Сообщение</string>
<string name="barcode_edit_random">случайный</string>

View file

@ -132,9 +132,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="found__pass">And %d more</string>
<string name="scan_finished_dialog_title">Scan finished.</string>
<string name="scan_finished_dialog_text">found %d passes</string>
<string name="scan_progressdialog_title">Searching…</string>
<string name="scan_progressdialog_message">Please wait.</string>
<string name="scan_dialog_send_background_button">background</string>
<string name="emtytrash_label">empty trash</string>
<string name="barcode_edit_hint_alternative_message">alternative Message</string>
<string name="barcode_edit_random">random</string>
@ -219,6 +216,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="error_no_permission_msg">Need permission to import pass</string>
<string name="error_no_permission_title">Permission Error</string>
<string name="scan_pass_message">Scanning for passes. Please wait.</string>
</resources>