Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] - Removed privacy feature for creators #328

Merged
merged 5 commits into from
Sep 12, 2018
Merged
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
13 changes: 11 additions & 2 deletions app/src/main/java/com/kickstarter/ui/activities/PrivacyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ class PrivacyActivity : BaseActivity<PrivacyViewModel.ViewModel>() {
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ this.displayPreferences(it) })

following_switch.setOnClickListener{ this.viewModel.inputs.optIntoFollowing(following_switch.isChecked) }
this.viewModel.outputs.hidePrivateProfileRow()
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( {
ViewUtils.setGone(private_profile_row, it)
ViewUtils.setGone(private_profile_text_view, it)
ViewUtils.setGone(public_profile_text_view, it)
})

following_switch.setOnClickListener { this.viewModel.inputs.optIntoFollowing(following_switch.isChecked) }
private_profile_switch.setOnClickListener { this.viewModel.inputs.showPublicProfile(private_profile_switch.isChecked) }
recommendations_switch.setOnClickListener { this.viewModel.inputs.optedOutOfRecommendations(recommendations_switch.isChecked) }
settings_request_data.setOnClickListener { showPrivacyWebpage(Secrets.Privacy.REQUEST_DATA) }
Expand All @@ -76,7 +85,7 @@ class PrivacyActivity : BaseActivity<PrivacyViewModel.ViewModel>() {
return this.followingConfirmationDialog!!
}

private fun showPrivacyWebpage(url : String) {
private fun showPrivacyWebpage(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/kickstarter/viewmodels/PrivacyViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.kickstarter.libs.ActivityViewModel
import com.kickstarter.libs.CurrentUserType
import com.kickstarter.libs.Environment
import com.kickstarter.libs.rx.transformers.Transformers
import com.kickstarter.libs.utils.IntegerUtils
import com.kickstarter.libs.utils.ListUtils
import com.kickstarter.libs.utils.ObjectUtils
import com.kickstarter.models.User
import com.kickstarter.services.ApiClientType
import com.kickstarter.ui.activities.PrivacyActivity
Expand All @@ -32,6 +34,9 @@ interface PrivacyViewModel {
/** Emits when Following switch should be turned back on after user cancels opting out. */
fun hideConfirmFollowingOptOutPrompt(): Observable<Void>

/** Emits when the user is a creator and we need to hide the private profile row. */
fun hidePrivateProfileRow(): Observable<Boolean>

/** Emits when user should be shown the Following confirmation dialog. */
fun showConfirmFollowingOptOutPrompt(): Observable<Void>

Expand All @@ -50,6 +55,7 @@ interface PrivacyViewModel {
private val userInput = PublishSubject.create<User>()

private val hideConfirmFollowingOptOutPrompt = BehaviorSubject.create<Void>()
private var hidePrivateProfileRow = BehaviorSubject.create<Boolean>()
private val showConfirmFollowingOptOutPrompt = BehaviorSubject.create<Void>()
private val userOutput = BehaviorSubject.create<User>()
private val updateSuccess = PublishSubject.create<Void>()
Expand All @@ -70,11 +76,19 @@ interface PrivacyViewModel {
.compose(bindToLifecycle())
.subscribe { this.currentUser.refresh(it) }

this.currentUser.observable()
val currentUser = this.currentUser.observable()

currentUser
.take(1)
.compose(bindToLifecycle())
.subscribe({ this.userOutput.onNext(it) })

currentUser
.compose(bindToLifecycle())
.filter(ObjectUtils::isNotNull)
.map { user -> IntegerUtils.isNonZero(user.createdProjectsCount()) }
.subscribe(this.hidePrivateProfileRow)

this.userInput
.concatMap<User>({ this.updateSettings(it) })
.compose(bindToLifecycle())
Expand Down Expand Up @@ -131,6 +145,8 @@ interface PrivacyViewModel {

override fun hideConfirmFollowingOptOutPrompt(): Observable<Void> = this.hideConfirmFollowingOptOutPrompt

override fun hidePrivateProfileRow(): Observable<Boolean> = this.hidePrivateProfileRow

override fun showConfirmFollowingOptOutPrompt(): Observable<Void> = this.showConfirmFollowingOptOutPrompt

override fun user(): Observable<User> = this.userOutput
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/activity_privacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
android:text="@string/We_use_your_activity_internally_to_make_recommendations_for_you" />

<LinearLayout
android:id="@+id/private_profile_row"
style="@style/SettingsLinearRow">

<LinearLayout
Expand All @@ -116,12 +117,14 @@
</LinearLayout>

<TextView
android:id="@+id/private_profile_text_view"
style="@style/NewsLetterTextView"
android:layout_marginBottom="@dimen/grid_1"
android:layout_marginTop="@dimen/grid_2"
android:text="@string/If_your_profile_is_private" />

<TextView
android:id="@+id/public_profile_text_view"
style="@style/NewsLetterTextView"
android:layout_marginBottom="@dimen/grid_3"
android:text="@string/If_your_profile_is_public" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.kickstarter.viewmodels

import com.kickstarter.KSRobolectricTestCase
import com.kickstarter.mock.factories.UserFactory
import com.kickstarter.libs.MockCurrentUser
import com.kickstarter.mock.factories.UserFactory
import com.kickstarter.models.User
import org.junit.Test
import rx.observers.TestSubscriber
Expand All @@ -12,6 +12,7 @@ class PrivacyViewModelTest : KSRobolectricTestCase() {

private val currentUserTest = TestSubscriber<User>()
private val hideConfirmFollowingOptOutPrompt = TestSubscriber<Void>()
private val hidePrivateProfile = TestSubscriber<Boolean>()
private val showConfirmFollowingOptOutPrompt = TestSubscriber<Void>()

private fun setUpEnvironment(user: User) {
Expand Down Expand Up @@ -86,6 +87,24 @@ class PrivacyViewModelTest : KSRobolectricTestCase() {
this.hideConfirmFollowingOptOutPrompt.assertNoValues()
}

@Test
fun testHidePrivateProfileRow_isFalse() {
val creator = UserFactory.creator()
setUpEnvironment(creator)

this.vm.outputs.hidePrivateProfileRow().subscribe(this.hidePrivateProfile)
this.hidePrivateProfile.assertValue(true)
}

@Test
fun testHidePrivateProfileRow_isTrue() {
val notCreator = UserFactory.user().toBuilder().createdProjectsCount(0).build()
setUpEnvironment(notCreator)

this.vm.outputs.hidePrivateProfileRow().subscribe(this.hidePrivateProfile)
this.hidePrivateProfile.assertValue(false)
}

@Test
fun testOptedOutOfRecommendations() {
val user = UserFactory.noRecommendations()
Expand Down