Skip to content

Commit

Permalink
improve sample-api34 ui
Browse files Browse the repository at this point in the history
  • Loading branch information
solrudev committed Dec 7, 2024
1 parent aa31131 commit 1c039d4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.transition.Fade
import androidx.transition.TransitionManager
import by.kirich1409.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch
import ru.solrudev.ackpine.AssetFileProvider
import ru.solrudev.ackpine.resources.ResolvableString
import ru.solrudev.ackpine.sample.updater.databinding.ActivityMainBinding
import ru.solrudev.ackpine.session.Progress
Expand All @@ -40,17 +41,21 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
setSupportActionBar(binding.toolbarMain)
binding.contentMain.layoutTransition?.enableTransitionType(LayoutTransition.CHANGING)
binding.buttonMainInstall.setOnClickListener {
binding.cardMainInstall.imageViewInstallIcon.setImageURI(
AssetFileProvider.getUriForAsset("ackpine_icon.webp")
)
binding.cardMainInstall.containerCardInstall.layoutTransition?.enableTransitionType(LayoutTransition.CHANGING)
binding.cardMainInstall.buttonInstall.setOnClickListener {
viewModel.onButtonClick()
}
lifecycleScope.launch {
viewModel.uiState.flowWithLifecycle(lifecycle).collect { uiState ->
binding.cardMainInstall.containerCardInstall.isVisible = uiState.isInstallationVisible
binding.buttonMainInstall.isEnabled = uiState.isCancellable
binding.buttonMainInstall.text = uiState.buttonText.resolve(this@MainActivity)
binding.cardMainInstall.progressBarInstall.isVisible = uiState.isInstallationVisible
binding.cardMainInstall.textViewInstallPercentage.isVisible = uiState.isInstallationVisible
binding.cardMainInstall.buttonInstall.isEnabled = uiState.isCancellable
binding.cardMainInstall.buttonInstall.text = uiState.buttonText.resolve(this@MainActivity)
setProgress(uiState.progress)
setError(uiState.error)
setError(uiState.error, uiState.isInstallationVisible)
}
}
}
Expand All @@ -66,12 +71,12 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
)
}

private fun setError(error: ResolvableString) = with(binding.cardMainInstall) {
private fun setError(error: ResolvableString, isInstallationVisible: Boolean) = with(binding.cardMainInstall) {
TransitionManager.beginDelayedTransition(root, Fade().apply { duration = 150 })
val hasError = !error.isEmpty
textViewInstall.isVisible = !hasError
progressBarInstall.isVisible = !hasError
textViewInstallPercentage.isVisible = !hasError
progressBarInstall.isVisible = !hasError && isInstallationVisible
textViewInstallPercentage.isVisible = !hasError && isInstallationVisible
textViewInstallError.isVisible = hasError
textViewInstallError.text = error.resolve(this@MainActivity)
}
Expand Down
16 changes: 5 additions & 11 deletions sample-api34/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,19 @@

</com.google.android.material.appbar.AppBarLayout>

<LinearLayout
<FrameLayout
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/content_padding_horizontal"
android:animateLayoutChanges="true"
android:gravity="center"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<include
android:id="@+id/card_main_install"
layout="@layout/card_install" />

<Button
android:id="@+id/button_main_install"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_install" />
android:layout_gravity="center"
layout="@layout/card_install" />

</LinearLayout>
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
51 changes: 39 additions & 12 deletions sample-api34/src/main/res/layout/card_install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,89 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/card_margin_vertical"
android:visibility="gone"
tools:visibility="visible">
android:animateLayoutChanges="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/card_min_height"
android:animateLayoutChanges="true"
android:padding="@dimen/card_padding">

<ImageView
android:id="@+id/imageView_install_icon"
android:layout_width="@dimen/application_icon_size"
android:layout_height="@dimen/application_icon_size"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@mipmap/ic_launcher" />

<TextView
android:id="@+id/textView_install_error"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/card_element_margin"
android:textColor="?colorError"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@id/button_install"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/imageView_install_icon"
tools:text="Install failed" />

<TextView
android:id="@+id/textView_install"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/install"
android:layout_marginHorizontal="@dimen/card_element_margin"
android:text="@string/installed_app_name"
android:textAppearance="?textAppearanceBodyMedium"
app:layout_constraintBottom_toTopOf="@id/progressBar_install"
app:layout_constraintEnd_toStartOf="@id/textView_install_percentage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/imageView_install_icon"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progressBar_install"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/card_element_margin"
android:layout_marginHorizontal="@dimen/card_element_margin"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@id/button_install"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView_install"
app:layout_constraintStart_toEndOf="@id/imageView_install_icon"
tools:visibility="visible"
tools:progress="28"
tools:showAnimationBehavior="none" />

<TextView
android:id="@+id/textView_install_percentage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/card_element_margin"
android:text="@string/default_percentage"
android:textAppearance="?textAppearanceBodyMedium"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@id/button_install"
app:layout_constraintBottom_toBottomOf="@id/textView_install"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/textView_install"
app:layout_constraintTop_toTopOf="@id/textView_install"
app:layout_constraintWidth="wrap_content"
app:layout_constraintTop_toTopOf="@id/textView_install"
tools:visibility="visible"
tools:text="28%" />

<Button
android:id="@+id/button_install"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_install"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
3 changes: 2 additions & 1 deletion sample-api34/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

<resources>
<dimen name="linear_progress_indicator_track_thickness">6dp</dimen>
<dimen name="application_icon_size">50dp</dimen>
<dimen name="card_margin_vertical">8dp</dimen>
<dimen name="card_min_height">80dp</dimen>
<dimen name="card_min_height">100dp</dimen>
<dimen name="card_padding">16dp</dimen>
<dimen name="card_element_margin">16dp</dimen>
<dimen name="content_padding_horizontal">16dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions sample-api34/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<resources>
<string name="app_name" translatable="false">Ackpine Updater</string>
<string name="installed_app_name" translatable="false">Ackpine</string>
<string name="default_percentage" translatable="false">0%</string>
<string name="percentage" translatable="false">%d%%</string>
<string name="install">Install</string>
Expand Down

0 comments on commit 1c039d4

Please sign in to comment.