Repository navigation
Added ability to display an image on the "Screen" activity #72
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,6 @@ dependencies { | |
| implementation libs.hilt.android | ||
| kapt libs.hilt.compiler | ||
|
|
||
| implementation libs.glide | ||
| annotationProcessor libs.compiler | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler is redundant here because we only use Glide to load images.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. I admit this one was a blind copy-pasting of some tutorial |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import android.content.ComponentName | |
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.content.ServiceConnection | ||
| import android.net.Uri | ||
| import android.os.Build | ||
| import android.os.Bundle | ||
| import android.os.IBinder | ||
|
|
@@ -18,6 +19,7 @@ import androidx.core.view.WindowCompat | |
| import androidx.core.view.WindowInsetsCompat | ||
| import androidx.core.view.updateLayoutParams | ||
| import androidx.core.view.updatePadding | ||
| import com.bumptech.glide.Glide | ||
| import com.github.deweyreed.tools.arch.observeEvent | ||
| import com.github.deweyreed.tools.helper.startDrawableAnimation | ||
| import com.github.deweyreed.tools.helper.stopDrawableAnimation | ||
|
|
@@ -30,6 +32,7 @@ import xyz.aprildown.timer.domain.entities.TimerEntity | |
| import xyz.aprildown.timer.domain.utils.Constants | ||
| import xyz.aprildown.timer.presentation.screen.ScreenViewModel | ||
| import xyz.aprildown.timer.presentation.stream.MachineContract | ||
| import java.io.File | ||
| import com.github.deweyreed.tools.R as RTools | ||
|
|
||
| @AndroidEntryPoint | ||
|
|
@@ -70,6 +73,17 @@ class ScreenActivity : BaseActivity() { | |
| } | ||
| } | ||
|
|
||
| intent?.getStringExtra(EXTRA_IMAGE_PATH)?.let { imagePath -> | ||
| if (imagePath.isNotEmpty()) { | ||
| val image = File(imagePath) | ||
| if (image.extension == "gif") | ||
| Glide.with(this).asGif().load(Uri.parse(imagePath)).into(binding.image) | ||
| else | ||
| Glide.with(this).asBitmap().load(Uri.parse(imagePath)).into(binding.image) | ||
| // binding.image.setImageURI(Uri.parse(imagePath)) | ||
| } | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glide can take care of everything for you, like this:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know. Thanks! |
||
| viewModel.setTimerId( | ||
| intent?.getIntExtra(Constants.EXTRA_TIMER_ID, TimerEntity.NULL_ID) | ||
| ?: TimerEntity.NULL_ID | ||
|
|
@@ -162,13 +176,9 @@ class ScreenActivity : BaseActivity() { | |
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| binding.imageRingtone.post { | ||
| binding.imageRingtone.startDrawableAnimation() | ||
| } | ||
| } | ||
|
|
||
| override fun onPause() { | ||
| binding.imageRingtone.stopDrawableAnimation() | ||
| super.onPause() | ||
| } | ||
|
|
||
|
|
@@ -190,15 +200,17 @@ class ScreenActivity : BaseActivity() { | |
| companion object { | ||
| private const val EXTRA_NAME = "extra_name" | ||
| private const val EXTRA_STEP_NAME = "extra_step_name" | ||
| private const val EXTRA_IMAGE_PATH = "extra_image_path" | ||
|
|
||
| @SuppressLint("StaticFieldLeak") | ||
| var screen: Activity? = null | ||
|
|
||
| fun intent(context: Context, id: Int, timerName: String, stepName: String): Intent { | ||
| fun intent(context: Context, id: Int, timerName: String, stepName: String, imagePath: String): Intent { | ||
| return Intent(context, ScreenActivity::class.java) | ||
| .putExtra(Constants.EXTRA_TIMER_ID, id) | ||
| .putExtra(EXTRA_NAME, timerName) | ||
| .putExtra(EXTRA_STEP_NAME, stepName) | ||
| .putExtra(EXTRA_IMAGE_PATH, imagePath) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,84 +9,67 @@ | |
|
|
||
| <TextView | ||
| android:id="@+id/textStepInfo" | ||
| android:layout_width="0dp" | ||
| android:layout_height="0dp" | ||
| android:layout_marginStart="8dp" | ||
| android:layout_marginEnd="8dp" | ||
| android:layout_width="191dp" | ||
| android:layout_height="113dp" | ||
| android:layout_marginTop="16dp" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Designing layouts with the layout inspector makes the layout inconsistent on different devices, which is why many developers prefer XML.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I didn't know using the layout designer was known to be a problem. Will remember this next time I work on native Android project |
||
| android:textColor="?colorOnPrimarySurface" | ||
| android:textSize="24sp" | ||
| app:autoSizeMaxTextSize="24sp" | ||
| app:autoSizeTextType="uniform" | ||
| app:layout_constrainedHeight="true" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toEndOf="@id/textTime" | ||
| app:layout_constraintStart_toStartOf="@id/textTime" | ||
| app:layout_constraintTop_toBottomOf="@id/textTime" | ||
| app:layout_constraintVertical_bias="0" | ||
| app:layout_constraintTop_toBottomOf="@+id/textTime" | ||
| tools:layout_editor_absoluteX="16dp" | ||
| tools:text="@tools:sample/lorem/random" /> | ||
|
|
||
| <ImageView | ||
| android:id="@+id/imageRingtone" | ||
| android:layout_width="128dp" | ||
| android:layout_height="128dp" | ||
| android:layout_marginStart="8dp" | ||
| android:layout_marginEnd="32dp" | ||
| android:id="@+id/image" | ||
| android:layout_width="384dp" | ||
| android:layout_height="368dp" | ||
| android:layout_marginStart="14dp" | ||
| android:layout_marginEnd="20dp" | ||
| android:importantForAccessibility="no" | ||
| android:scaleType="fitXY" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toStartOf="@id/btnStop" | ||
| app:layout_constraintHorizontal_bias="0.5" | ||
| app:layout_constraintStart_toEndOf="@id/textTime" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| app:srcCompat="@drawable/ic_anim_ringing" | ||
| app:tint="?colorOnPrimarySurface" /> | ||
| android:scaleType="center" | ||
| app:layout_constraintEnd_toStartOf="@+id/btnStop" | ||
| app:layout_constraintStart_toEndOf="@+id/textStepInfo" | ||
| tools:layout_editor_absoluteY="21dp" /> | ||
|
|
||
| <TextView | ||
| android:id="@+id/textTime" | ||
| android:layout_width="0dp" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginStart="32dp" | ||
| android:layout_marginBottom="8dp" | ||
| android:layout_width="188dp" | ||
| android:layout_height="104dp" | ||
| android:layout_marginTop="21dp" | ||
| android:fontFamily="@font/digital_numbers_colon" | ||
| android:maxLines="1" | ||
| android:paddingTop="24dp" | ||
| android:paddingBottom="24dp" | ||
| android:textColor="?colorOnPrimarySurface" | ||
| android:textSize="108sp" | ||
| app:autoSizeTextType="uniform" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toStartOf="@id/imageRingtone" | ||
| app:layout_constraintHorizontal_bias="0.5" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@+id/btnAddOneMinute" | ||
| tools:layout_editor_absoluteX="16dp" | ||
| tools:text="12:34" /> | ||
|
|
||
| <Button | ||
| android:id="@+id/btnAddOneMinute" | ||
| style="@style/Widget.MaterialComponents.Button.TextButton" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginStart="16dp" | ||
| android:text="@string/one_action_add_one_minute" | ||
| android:textColor="?colorOnPrimarySurface" | ||
| app:layout_constraintBottom_toTopOf="@id/textTime" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:rippleColor="?colorOnPrimarySurface" /> | ||
| app:rippleColor="?colorOnPrimarySurface" | ||
| tools:layout_editor_absoluteX="16dp" | ||
| tools:layout_editor_absoluteY="16dp" /> | ||
|
|
||
| <com.google.android.material.floatingactionbutton.FloatingActionButton | ||
| android:id="@+id/btnStop" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="8dp" | ||
| android:layout_width="90dp" | ||
| android:layout_height="124dp" | ||
| android:contentDescription="@string/stop" | ||
| app:fabCustomSize="156dp" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintHorizontal_bias="0.5" | ||
| app:layout_constraintStart_toEndOf="@id/imageRingtone" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| app:fabCustomSize="94dp" | ||
| app:maxImageSize="72dp" | ||
| app:srcCompat="@drawable/ic_stop" /> | ||
| app:srcCompat="@drawable/ic_stop" | ||
| tools:layout_editor_absoluteX="625dp" | ||
| tools:layout_editor_absoluteY="165dp" /> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registering a launcher after onCreate will crash the app. If I remember correctly, you must create the launcher before or in onCreate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I indeed noticed that with "EditActivity.kt", which has this fixed. I leaved it that way here because I didn't know how to accommodate the difference between this file and the other. Beside, I still don't know when this file intervenes in the app