Skip to content

Commit

Permalink
Merge pull request #200 from Adventech/tm/fix/gc_prompt
Browse files Browse the repository at this point in the history
GC prompt fixes
  • Loading branch information
TinasheMzondiwa authored May 21, 2021
2 parents 59d5e7d + ad2ce22 commit 7a6e376
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 103 deletions.
9 changes: 9 additions & 0 deletions common/design/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M18.3,5.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L12,10.59 7.11,5.7c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41L10.59,12 5.7,16.89c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0L12,13.41l4.89,4.89c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L13.41,12l4.89,-4.89c0.38,-0.38 0.38,-1.02 0,-1.4z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
2 changes: 1 addition & 1 deletion common/design/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<color name="ss_color_overlay">#5b000000</color>
<color name="ss_color_display_theme_sepia">#f2dec3</color>
<color name="ss_color_display_theme_dark">#484848</color>
<color name="ss_blue">#005EC7</color>
<color name="ss_blue">#2E5797</color>
<color name="ss_blue_dark">#27407d</color>
<color name="ss_red_300">#FF5C44</color>
<color name="ss_red_600">#E51A19</color>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import app.ss.lessons.data.model.SSQuarterly
Expand All @@ -45,6 +43,7 @@ import com.cryart.sabbathschool.core.navigation.AppNavigator
import com.cryart.sabbathschool.core.navigation.Destination
import com.cryart.sabbathschool.lessons.R
import com.cryart.sabbathschool.lessons.databinding.SsActivityQuarterliesBinding
import com.cryart.sabbathschool.lessons.databinding.SsPromptAppReBrandingBinding
import com.cryart.sabbathschool.lessons.ui.base.SSBaseActivity
import com.cryart.sabbathschool.lessons.ui.languages.LanguagesListFragment
import com.cryart.sabbathschool.lessons.ui.lessons.SSLessonsActivity
Expand All @@ -67,8 +66,6 @@ class QuarterliesActivity : SSBaseActivity() {

private val quarterliesAdapter: SSQuarterliesAdapter = SSQuarterliesAdapter()

private var brandingAlertDialog: AlertDialog? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
Expand Down Expand Up @@ -161,18 +158,17 @@ class QuarterliesActivity : SSBaseActivity() {
}

private fun showAppReBrandingPrompt() {
val view = layoutInflater.inflate(R.layout.ss_prompt_app_re_branding, null)
view.findViewById<View>(R.id.btn_ok).setOnClickListener {
brandingAlertDialog?.dismiss()
brandingAlertDialog = null
viewModel.reBrandingPromptSeen()
}
val binding = SsPromptAppReBrandingBinding.inflate(layoutInflater)

brandingAlertDialog = MaterialAlertDialogBuilder(this)
.setView(view)
.setCancelable(false)
val alertDialog = MaterialAlertDialogBuilder(this)
.setView(binding.root)
.create()
brandingAlertDialog?.show()

binding.btnClose.setOnClickListener {
alertDialog.dismiss()
}

alertDialog.show()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class QuarterliesViewModel @Inject constructor(
mutableShowLanguagePrompt.call()
}
} else {
_appReBranding.emit(!ssPrefs.isAppReBrandingPromptShown())
handleBrandingPrompt()
}
} else {
mutableViewState.postValue(ViewState.Error())
Expand All @@ -120,7 +120,10 @@ class QuarterliesViewModel @Inject constructor(
ssPrefs.setLanguagePromptSeen()
}

fun reBrandingPromptSeen() {
ssPrefs.setAppReBrandingShown()
private suspend fun handleBrandingPrompt() {
if (!ssPrefs.isAppReBrandingPromptShown()) {
ssPrefs.setAppReBrandingShown()
_appReBranding.emit(true)
}
}
}
116 changes: 61 additions & 55 deletions features/lessons/src/main/res/layout/ss_prompt_app_re_branding.xml
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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:fillViewport="true">
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fillViewport="true">

<ImageView
android:id="@+id/sspm_logo"
android:layout_width="@dimen/sspm_logo_size"
android:layout_height="@dimen/sspm_logo_size"
android:contentDescription="@string/sspm_logo_content_description"
android:src="@drawable/logo_sspm"
app:layout_constraintBottom_toTopOf="@id/content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/content"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingHorizontal="@dimen/spacing_medium_large"
android:paddingVertical="@dimen/spacing_normal"
android:text="@string/sspm_re_branding_message"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorPrimary"
android:letterSpacing="0.01"
app:fontFamily="@font/lato_regular"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="match_parent">

<ImageView
android:id="@+id/sspm_logo"
android:layout_width="@dimen/sspm_logo_size"
android:layout_height="@dimen/sspm_logo_size"
android:contentDescription="@string/sspm_logo_content_description"
android:src="@drawable/logo_sspm"
app:layout_constraintBottom_toTopOf="@id/content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:letterSpacing="0.01"
android:paddingHorizontal="@dimen/spacing_medium_large"
android:paddingVertical="@dimen/spacing_normal"
android:text="@string/sspm_re_branding_message"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorPrimary"
app:fontFamily="@font/lato_regular"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/gc_sspm_logo"
android:layout_width="@dimen/gc_sspm_logo_width"
android:layout_height="@dimen/gc_sspm_logo_height"
android:contentDescription="@string/gc_sspm_logo_content_description"
android:scaleType="centerInside"
android:src="@drawable/gc_sspm_logo"
app:layout_constraintBottom_toTopOf="@id/btn_ok"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content"
app:tint="@color/ss_logo_tint" />
<ImageView
android:id="@+id/gc_sspm_logo"
android:layout_width="@dimen/gc_sspm_logo_width"
android:layout_height="@dimen/gc_sspm_logo_height"
android:layout_marginBottom="@dimen/spacing_medium"
android:contentDescription="@string/gc_sspm_logo_content_description"
android:scaleType="centerInside"
android:src="@drawable/gc_sspm_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content"
app:tint="@color/ss_logo_tint" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/spacing_medium"
android:text="@android:string/ok"
style="@style/Widget.MaterialComponents.Button.TextButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<ImageButton
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_medium"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/blank"
android:src="@drawable/ic_close"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.test.runBlockingTest
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldBeFalse
import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldBeTrue
import org.junit.Before
Expand Down Expand Up @@ -172,42 +171,15 @@ class QuarterliesViewModelTest {
every { mockSSPrefs.getLastQuarterlyIndex() }.returns(null)
every { mockSSPrefs.isLanguagePromptSeen() }.returns(true)
every { mockSSPrefs.isAppReBrandingPromptShown() }.returns(false)
every { mockSSPrefs.setAppReBrandingShown() }.returns(Unit)

viewModel.appReBrandingFlow.test {
viewModel.viewCreated()

expectItem().shouldBeTrue()
}
}

@Test
fun `should emit false for branding prompt flow when prompt was seen`() = coroutinesTestRule.runBlockingTest {
val language = "de"
val flow: Flow<Resource<List<SSQuarterly>>> = callbackFlow {
sendBlocking(Resource.success(emptyList()))
awaitClose { }
verify { mockSSPrefs.setAppReBrandingShown() }
}
every { mockRepository.getQuarterlies(language) }.returns(flow)
every { mockSSPrefs.getLanguageCode() }.returns(language)
every { mockSSPrefs.setLanguageCode(language) }.returns(Unit)
every { mockSSPrefs.getLastQuarterlyIndex() }.returns(null)
every { mockSSPrefs.isLanguagePromptSeen() }.returns(true)
every { mockSSPrefs.isAppReBrandingPromptShown() }.returns(true)

viewModel.appReBrandingFlow.test {
viewModel.viewCreated()

expectItem().shouldBeFalse()
}
}

@Test
fun `should set branding prompt as seen`() {
every { mockSSPrefs.setAppReBrandingShown() }.returns(Unit)

viewModel.reBrandingPromptSeen()

verify { mockSSPrefs.setAppReBrandingShown() }
}

@Test
Expand Down

0 comments on commit 7a6e376

Please sign in to comment.