This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Edit xml layout * Add route, presenter, and fragment Button clicks and dialog Update dependencies Edit presenter tests Routing stuff Usable state with spinner Buttons working Password visibility in edit mode Lint View Create popup item and insert menu into detail view's kebab buttton * Popup menu and click listener Dropdown menu and formatting Update list - in progress DataStoreTest - mocked up test, stuck on init Datastore update item detail test * Save edited changes Lint Update dependencies Edit unit tests Add sync to datastore editing. Update var name in robot and screenshot tests Reformatting dropdown menu and edit view Adding inclusive popup to edit->detail view nav definition Address nullable server passwords for delete and edit. Remove unused string. Remove learn more clicks from test Refactoring pushError into a helper method.
- Loading branch information
Elise Richards
authored
Sep 3, 2019
1 parent
5a83079
commit c435688
Showing
54 changed files
with
1,368 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
app/src/main/java/mozilla/lockbox/adapter/DeleteItemAdapter.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
app/src/main/java/mozilla/lockbox/presenter/EditItemPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package mozilla.lockbox.presenter | ||
|
||
import io.reactivex.Observable | ||
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread | ||
import io.reactivex.rxkotlin.addTo | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import mozilla.appservices.logins.ServerPassword | ||
import mozilla.lockbox.action.DataStoreAction | ||
import mozilla.lockbox.action.DialogAction | ||
import mozilla.lockbox.action.ItemDetailAction | ||
import mozilla.lockbox.action.RouteAction | ||
import mozilla.lockbox.extensions.filterNotNull | ||
import mozilla.lockbox.extensions.toDetailViewModel | ||
import mozilla.lockbox.flux.Dispatcher | ||
import mozilla.lockbox.flux.Presenter | ||
import mozilla.lockbox.model.ItemDetailViewModel | ||
import mozilla.lockbox.store.DataStore | ||
import mozilla.lockbox.store.ItemDetailStore | ||
import mozilla.lockbox.support.Constant | ||
import mozilla.lockbox.support.pushError | ||
|
||
interface EditItemDetailView { | ||
var isPasswordVisible: Boolean | ||
val togglePasswordClicks: Observable<Unit> | ||
val deleteClicks: Observable<Unit> | ||
val learnMoreClicks: Observable<Unit> | ||
val closeEntryClicks: Observable<Unit> | ||
val saveEntryClicks: Observable<Unit> | ||
val hostnameChanged: Observable<CharSequence> | ||
val usernameChanged: Observable<CharSequence> | ||
val passwordChanged: Observable<CharSequence> | ||
fun updateItem(item: ItemDetailViewModel) | ||
fun closeKeyboard() | ||
} | ||
|
||
@ExperimentalCoroutinesApi | ||
class EditItemPresenter( | ||
private val view: EditItemDetailView, | ||
val itemId: String?, | ||
private val dispatcher: Dispatcher = Dispatcher.shared, | ||
private val dataStore: DataStore = DataStore.shared, | ||
private val itemDetailStore: ItemDetailStore = ItemDetailStore.shared | ||
) : Presenter() { | ||
|
||
private var credentials: ServerPassword? = null | ||
|
||
override fun onViewReady() { | ||
val itemId = this.itemId ?: return | ||
|
||
dataStore.get(itemId) | ||
.observeOn(mainThread()) | ||
.filterNotNull() | ||
.doOnNext { credentials = it } | ||
.map { it.toDetailViewModel() } | ||
.subscribe(view::updateItem) | ||
.addTo(compositeDisposable) | ||
|
||
view.isPasswordVisible = false | ||
|
||
itemDetailStore.isPasswordVisible | ||
.subscribe { view.isPasswordVisible = it } | ||
.addTo(compositeDisposable) | ||
|
||
view.togglePasswordClicks | ||
.subscribe { | ||
dispatcher.dispatch(ItemDetailAction.TogglePassword(view.isPasswordVisible.not())) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.learnMoreClicks | ||
.subscribe { | ||
dispatcher.dispatch(RouteAction.OpenWebsite(Constant.Faq.uri)) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.deleteClicks | ||
.subscribe { | ||
if (credentials != null) { | ||
dispatcher.dispatch(DataStoreAction.Delete(credentials!!)) | ||
dispatcher.dispatch(RouteAction.ItemList) | ||
} else { | ||
pushError( | ||
NullPointerException("Credentials are null"), | ||
"Error editing credential with id ${credentials?.id}" | ||
) | ||
} | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.closeEntryClicks | ||
.subscribe { | ||
dispatcher.dispatch(DialogAction.DiscardChangesDialog(credentials!!.id)) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.hostnameChanged | ||
.subscribe { | ||
updateCredentials(newHostname = it) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.usernameChanged | ||
.subscribe { | ||
updateCredentials(newUsername = it) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.passwordChanged | ||
.subscribe { | ||
updateCredentials(newPassword = it) | ||
} | ||
.addTo(compositeDisposable) | ||
|
||
view.saveEntryClicks | ||
.subscribe { | ||
if (credentials != null) { | ||
dispatcher.dispatch(DataStoreAction.UpdateItemDetail(credentials!!)) | ||
view.closeKeyboard() | ||
dispatcher.dispatch(RouteAction.ItemList) | ||
} else { | ||
pushError( | ||
NullPointerException("Credentials are null"), | ||
"Error editing credential with id ${credentials?.id}" | ||
) | ||
} | ||
} | ||
.addTo(compositeDisposable) | ||
} | ||
|
||
private fun updateCredentials( | ||
newHostname: CharSequence? = null, | ||
newUsername: CharSequence? = null, | ||
newPassword: CharSequence? = null | ||
) { | ||
try { | ||
credentials = ServerPassword( | ||
id = credentials?.id.orEmpty(), | ||
hostname = newHostname?.toString() ?: credentials?.hostname.orEmpty(), | ||
username = newUsername?.toString() ?: credentials?.username, | ||
password = newPassword?.toString() ?: credentials?.password.orEmpty(), | ||
httpRealm = credentials?.httpRealm, | ||
formSubmitURL = credentials?.formSubmitURL | ||
) | ||
} catch (exception: NullPointerException) { | ||
pushError(exception, "Error editing credential with id ${credentials?.id}") | ||
} | ||
} | ||
} |
Oops, something went wrong.