Skip to content

Commit

Permalink
Version 1.0.0 Fixes (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner authored Nov 27, 2018
1 parent e486a07 commit 550704f
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.view.View
import android.widget.TextView
import com.jakewharton.rxbinding2.view.clicks
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -15,9 +16,11 @@ import pm.gnosis.heimdall.R
import pm.gnosis.heimdall.helpers.ToolbarHelper
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.ViewModelActivity
import pm.gnosis.heimdall.utils.setCompoundDrawableResource
import pm.gnosis.svalinn.common.utils.getColorCompat
import pm.gnosis.svalinn.common.utils.snackbar
import pm.gnosis.svalinn.common.utils.subscribeForResult
import pm.gnosis.utils.nullOnThrow
import pm.gnosis.utils.words
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -33,11 +36,17 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
@Inject
lateinit var adapter: ConfirmRecoveryPhraseAdapter

private var scrollRunnable: Runnable? = null

override fun layout() = R.layout.layout_confirm_recovery_phrase

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

viewModel.setup(intent.getStringExtra(EXTRA_RECOVERY_PHRASE))

layout_confirm_recovery_phrase_submit.setCompoundDrawableResource(right = R.drawable.ic_arrow_forward_24dp)

layout_confirm_recovery_phrase_recycler_view.apply {
setHasFixedSize(true)
layoutManager = GridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false)
Expand Down Expand Up @@ -67,7 +76,7 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
layout_confirm_recovery_phrase_word_4.text = recoveryPhraseWords[randomPositions[3]]
layout_confirm_recovery_phrase_word_4.isClickable = true

adapter.setWords(recoveryPhraseWords, randomPositions)
scrollToWord(adapter.setWords(recoveryPhraseWords, randomPositions))
}

override fun onStart() {
Expand Down Expand Up @@ -96,6 +105,11 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
disposables += toolbarHelper.setupShadow(layout_confirm_recovery_phrase_toolbar_shadow, layout_confirm_recovery_phrase_scroll_view)
}

override fun onPause() {
scrollRunnable?.let { layout_confirm_recovery_phrase_scroll_view.removeCallbacks(it) }
super.onPause()
}

private fun onIncorrectPositions(incorrectPositions: Set<Int>) {
if (incorrectPositions.isEmpty()) {
isRecoveryPhraseConfirmed()
Expand All @@ -110,7 +124,7 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
private fun subscribeWordSelection(wordView: TextView) =
wordView.clicks().subscribeBy(
onNext = {
adapter.pushWord(wordView.text.toString())
scrollToWord(adapter.pushWord(wordView.text.toString()))
setWord(isEnabled = false, wordView = wordView)
},
onError = Timber::e
Expand All @@ -119,16 +133,28 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
override fun onBackPressed() {
if (adapter.getSelectedCount() == 0) super.onBackPressed()
else {
val poppedWord = adapter.popWord()
val (poppedWord, nextActiveIndex) = adapter.popWord()
when (poppedWord) {
layout_confirm_recovery_phrase_word_1.text -> setWord(isEnabled = true, wordView = layout_confirm_recovery_phrase_word_1)
layout_confirm_recovery_phrase_word_2.text -> setWord(isEnabled = true, wordView = layout_confirm_recovery_phrase_word_2)
layout_confirm_recovery_phrase_word_3.text -> setWord(isEnabled = true, wordView = layout_confirm_recovery_phrase_word_3)
layout_confirm_recovery_phrase_word_4.text -> setWord(isEnabled = true, wordView = layout_confirm_recovery_phrase_word_4)
}
scrollToWord(nextActiveIndex)
}
}

private fun scrollToWord(wordPosition: Int) {
scrollRunnable?.let { layout_confirm_recovery_phrase_scroll_view.removeCallbacks(it) }
scrollRunnable = Runnable {
layout_confirm_recovery_phrase_recycler_view.layoutManager.findViewByPosition(wordPosition)?.let {
// Android sometimes doesn't like this if this is done at the wrong point in time
nullOnThrow { layout_confirm_recovery_phrase_scroll_view.requestChildFocus(it, it) }
}
}
layout_confirm_recovery_phrase_scroll_view.postDelayed(scrollRunnable, SCROLL_DELAY_MS)
}

private fun setWord(isEnabled: Boolean, wordView: TextView) {
wordView.isClickable = isEnabled
wordView.setTextColor(getColorCompat(if (isEnabled) R.color.word_recovery_phrase_picker else R.color.word_recovery_phrase_picker_disabled))
Expand All @@ -144,9 +170,8 @@ abstract class ConfirmRecoveryPhraseActivity<VM : ConfirmRecoveryPhraseContract>
randomWordsDisposable?.dispose()
}

override fun layout() = R.layout.layout_confirm_recovery_phrase

companion object {
private const val SCROLL_DELAY_MS = 400L
const val EXTRA_RECOVERY_PHRASE = "extra.string.recovery_phrase"

fun createIntent(context: Context, recoveryPhrase: String) = Intent(context, ConfirmRecoveryPhraseActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,27 @@ class ConfirmRecoveryPhraseAdapter @Inject constructor() : RecyclerView.Adapter<

override fun getItemCount() = words.size

fun setWords(words: List<String>, inputPositions: List<Int>) {
/**
* Returns the index of the word that is active or -1 if no word is active
*/
fun setWords(words: List<String>, inputPositions: List<Int>): Int {
this.words.clear()
this.words.addAll(words.mapIndexed { index, word ->
if (inputPositions.contains(index)) Word(word = "", isSelectable = true, isActive = false, isError = false)
else Word(word = word, isSelectable = false, isActive = false, isError = false)
})
this.words.firstOrNull { it.isSelectable }?.let { it.isActive = true }
val currentActiveWord = this.words.indexOfFirst { it.isSelectable }
if (currentActiveWord != -1) {
this.words[currentActiveWord].isActive = true
}
notifyDataSetChanged()
return currentActiveWord
}

fun pushWord(word: String) {
/**
* Returns the index of the word that is active or -1 if no word is active
*/
fun pushWord(word: String): Int {
// Set the current active word to inactive
val currentActiveWordIndex = words.indexOfFirst { it.isActive }
if (currentActiveWordIndex != -1) {
Expand All @@ -68,9 +78,13 @@ class ConfirmRecoveryPhraseAdapter @Inject constructor() : RecyclerView.Adapter<
words[nextActiveWordIndex].isActive = true
notifyItemChanged(nextActiveWordIndex)
}
return nextActiveWordIndex
}

fun popWord(): String {
/**
* Returns the word that was popped and the next active position or -1 if no position is active
*/
fun popWord(): Pair<String, Int> {
var poppedWord = ""

// Remove the current active status
Expand All @@ -91,7 +105,7 @@ class ConfirmRecoveryPhraseAdapter @Inject constructor() : RecyclerView.Adapter<
notifyItemChanged(wordToPopIndex)
}

return poppedWord
return poppedWord to wordToPopIndex
}

fun observeSelectedCount(): Observable<Int> = selectedWordCountSubject.startWith(getSelectedCount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import pm.gnosis.heimdall.helpers.ToolbarHelper
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.BaseActivity
import pm.gnosis.heimdall.utils.scaleBitmapToWidth
import pm.gnosis.heimdall.utils.setCompoundDrawableResource
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -32,6 +33,7 @@ abstract class RecoveryPhraseIntroActivity : BaseActivity() {
super.onCreate(savedInstanceState)
inject()
setContentView(R.layout.layout_recovery_phrase_intro)
layout_recovery_phrase_intro_next.setCompoundDrawableResource(right = R.drawable.ic_arrow_forward_24dp)
}

override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import pm.gnosis.heimdall.R
import pm.gnosis.heimdall.helpers.ToolbarHelper
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.ViewModelActivity
import pm.gnosis.heimdall.utils.setCompoundDrawableResource
import timber.log.Timber
import javax.inject.Inject

abstract class SetupRecoveryPhraseActivity<VM : SetupRecoveryPhraseContract> : ViewModelActivity<VM>() {
override fun screenId(): ScreenId = ScreenId.CONFIRM_RECOVERY_PHRASE

@Inject
lateinit var toolbarHelper: ToolbarHelper

Expand All @@ -34,6 +35,8 @@ abstract class SetupRecoveryPhraseActivity<VM : SetupRecoveryPhraseContract> : V
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_setup_recovery_phrase)

layout_setup_recovery_phrase_next.setCompoundDrawableResource(right = R.drawable.ic_arrow_forward_24dp)

layout_setup_recovery_phrase_recycler_view.apply {
setHasFixedSize(true)
layoutManager = GridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.BaseFragment
import pm.gnosis.heimdall.ui.safe.create.CreateSafeIntroActivity
import pm.gnosis.heimdall.ui.safe.recover.safe.CheckSafeActivity
import pm.gnosis.heimdall.ui.safe.recover.safe.RecoverSafeIntroActivity
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -37,7 +38,7 @@ class NoSafesFragment : BaseFragment() {
.subscribeBy(onNext = { startActivity(CreateSafeIntroActivity.createIntent(context!!)) }, onError = Timber::e)

disposables += layout_no_safes_recover_safe.clicks()
.subscribeBy(onNext = { startActivity(CheckSafeActivity.createIntent(context!!)) }, onError = Timber::e)
.subscribeBy(onNext = { startActivity(RecoverSafeIntroActivity.createIntent(context!!)) }, onError = Timber::e)
}

override fun inject(component: ApplicationComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import pm.gnosis.heimdall.ui.safe.recover.extension.ReplaceExtensionPairingActiv
import pm.gnosis.heimdall.ui.safe.recover.recoveryphrase.ScanExtensionAddressActivity
import pm.gnosis.heimdall.ui.safe.recover.recoveryphrase.SetupNewRecoveryPhraseIntroActivity
import pm.gnosis.heimdall.ui.safe.recover.safe.CheckSafeActivity
import pm.gnosis.heimdall.ui.safe.recover.safe.RecoverSafeIntroActivity
import pm.gnosis.heimdall.ui.safe.recover.safe.submit.RecoveringSafeFragment
import pm.gnosis.heimdall.ui.settings.general.GeneralSettingsActivity
import pm.gnosis.heimdall.ui.tokens.manage.ManageTokensActivity
Expand Down Expand Up @@ -182,7 +183,7 @@ class SafeMainActivity : ViewModelActivity<SafeMainContract>() {
}

layout_safe_main_recover_safe.setOnClickListener {
startActivity(CheckSafeActivity.createIntent(this))
startActivity(RecoverSafeIntroActivity.createIntent(this))
closeDrawer()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import pm.gnosis.heimdall.di.modules.ViewModule
import pm.gnosis.heimdall.helpers.ToolbarHelper
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.BaseActivity
import pm.gnosis.heimdall.utils.setCompoundDrawableResource
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -28,6 +29,8 @@ class RecoverSafeIntroActivity: BaseActivity() {
super.onCreate(savedInstanceState)
inject()
setContentView(R.layout.layout_recover_safe_intro)

layout_recover_safe_intro_next.setCompoundDrawableResource(right = R.drawable.ic_arrow_forward_24dp)
}

override fun onStart() {
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/layout_confirm_recovery_phrase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_confirm_recovery_phrase_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down Expand Up @@ -53,8 +54,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -173,16 +174,16 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@drawable/selectable_background"
android:drawableEnd="@drawable/ic_arrow_forward_24dp"
android:drawablePadding="12dp"
android:gravity="center"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingStart="12dp"
android:text="@string/submit"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/layout_confirm_recovery_phrase_bottom_bar_container"
app:layout_constraintEnd_toEndOf="@+id/layout_confirm_recovery_phrase_bottom_bar_container"
app:layout_constraintTop_toTopOf="@+id/layout_confirm_recovery_phrase_bottom_bar_container" />
app:layout_constraintTop_toTopOf="@+id/layout_confirm_recovery_phrase_bottom_bar_container"
tools:drawableEnd="@drawable/ic_arrow_forward_24dp" />

<View
android:id="@+id/layout_confirm_recovery_phrase_toolbar_background"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/layout_create_safe_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@
android:id="@+id/layout_create_safe_intro_title"
style="@style/WhiteTheme.ToolbarTitle"
android:layout_width="0dp"
android:layout_height="@dimen/toolbar_height"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/toolbar_height"
android:text="@string/guidelines"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/layout_create_safe_intro_back_arrow"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/layout_recover_safe_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
android:id="@+id/layout_recover_safe_intro_scroll"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
android:fillViewport="true"
android:paddingBottom="24dp"
android:paddingTop="24dp"
app:layout_constraintBottom_toTopOf="@+id/layout_recover_safe_intro_bottom_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -24,7 +27,6 @@
android:id="@+id/layout_recover_safe_intro_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:src="@drawable/ic_safe_inprogress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -111,7 +113,6 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@drawable/selectable_background"
android:drawableEnd="@drawable/ic_arrow_forward_24dp"
android:drawablePadding="16dp"
android:gravity="center"
android:paddingEnd="16dp"
Expand All @@ -122,6 +123,7 @@
app:layout_constraintBottom_toBottomOf="@+id/layout_recover_safe_intro_bottom_bar"
app:layout_constraintEnd_toEndOf="@+id/layout_recover_safe_intro_bottom_bar"
app:layout_constraintTop_toTopOf="@+id/layout_recover_safe_intro_bottom_bar"
tools:drawableEnd="@drawable/ic_arrow_forward_24dp"
tools:enabled="false" />

<View
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/layout/layout_recovery_phrase_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -37,11 +38,11 @@
android:id="@+id/layout_recovery_phrase_intro_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="40dp"
android:lineSpacingExtra="7sp"
android:paddingStart="56dp"
android:paddingEnd="56dp"
android:paddingStart="56dp"
android:text="@string/layout_recovery_phrase_intro_description"
android:textColor="@color/battleship_grey"
android:textSize="15sp"
Expand Down Expand Up @@ -110,17 +111,17 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@drawable/selectable_background"
android:drawableEnd="@drawable/ic_arrow_forward_24dp"
android:drawablePadding="16dp"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:text="@string/get_my_recovery_phrase"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/layout_recovery_phrase_intro_bottom_bar"
app:layout_constraintEnd_toEndOf="@+id/layout_recovery_phrase_intro_bottom_bar"
app:layout_constraintTop_toTopOf="@+id/layout_recovery_phrase_intro_bottom_bar" />
app:layout_constraintTop_toTopOf="@+id/layout_recovery_phrase_intro_bottom_bar"
tools:drawableEnd="@drawable/ic_arrow_forward_24dp" />

<View
android:id="@+id/layout_recovery_phrase_intro_toolbar_shadow"
Expand Down
Loading

0 comments on commit 550704f

Please sign in to comment.