Skip to content

Commit

Permalink
Uses glide to avoid crash in tutorial due to out of memory (raw image…
Browse files Browse the repository at this point in the history
… is big); fail gracefully for all other errors
  • Loading branch information
IzHoBX committed Jun 27, 2020
1 parent ecdc8e6 commit 8bd1b69
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ dependencies {
implementation 'com.google.firebase:firebase-config-ktx:19.1.4'
implementation 'com.google.firebase:firebase-analytics-ktx:17.4.3'

//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'

api 'com.google.guava:guava:28.2-jre'

testImplementation 'junit:junit:4.12'
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/izho/saveentry/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class MainActivity : AppCompatActivity() {

tabs.post {
if(!Prefs.hasSeenTutorial(this)) {
TutorialManager(this).showTutorial(R.id.view_pager)
try {
TutorialManager(this).showTutorial(R.id.view_pager)
} catch (e:Throwable) {
//likely due to the device memory is unable to load the raw image
Prefs.setHasSeenTutorial(this, true)
}
}
}
SafeEntryHelper.update()
Expand Down
22 changes: 7 additions & 15 deletions app/src/main/java/com/izho/saveentry/utils/TutorialManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.izho.saveentry.utils

import android.app.ActionBar
import android.content.Intent
import android.net.Uri
import android.os.Bundle
Expand All @@ -14,14 +15,15 @@ import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.bumptech.glide.Glide
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.izho.saveentry.R
import okhttp3.internal.immutableListOf


const val TUTORIAL_POPUP_WIDTH = 900
const val TUTORIAL_POPUP_HEIGHT = 1855
const val TUTORIAL_POPUP_WIDTH = WindowManager.LayoutParams.WRAP_CONTENT
const val TUTORIAL_POPUP_HEIGHT = WindowManager.LayoutParams.WRAP_CONTENT

class TutorialManager(val activity: AppCompatActivity) {
fun showTutorial(viewPagerId:Int) {
Expand Down Expand Up @@ -129,26 +131,18 @@ class TutorialManager(val activity: AppCompatActivity) {
): View? {
return inflater.inflate(R.layout.fragment_tutorial, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}

class WidgetTutorialFragment : TutorialFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.findViewById<ImageView>(R.id.imageView).setImageDrawable(activity?.getDrawable(
R.drawable.check_in_home
))
Glide.with(this).load(R.drawable.check_in_home).into(view.findViewById<ImageView>(R.id.imageView))
super.onViewCreated(view, savedInstanceState)
}
}

class TileTutorialFragment : TutorialFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.findViewById<ImageView>(R.id.imageView).setImageDrawable(activity?.getDrawable(
R.drawable.check_in_lock
))
Glide.with(this).load(R.drawable.check_in_lock).into(view.findViewById<ImageView>(R.id.imageView))
super.onViewCreated(view, savedInstanceState)
}
}
Expand All @@ -159,9 +153,7 @@ class TutorialManager(val activity: AppCompatActivity) {
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.findViewById<ImageView>(R.id.imageView).setImageDrawable(activity?.getDrawable(
R.drawable.add_to_fav
))
Glide.with(this).load(R.drawable.add_to_fav).into(view.findViewById<ImageView>(R.id.imageView))
super.onViewCreated(view, savedInstanceState)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_tutorial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
android:padding="2dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="590dp"
android:layout_height="wrap_content"
android:src="@drawable/check_in_home"/>


Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout/tutorial_popup.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
Expand All @@ -13,9 +13,9 @@
<androidx.viewpager2.widget.ViewPager2
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="57dp"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"/>

<com.google.android.material.tabs.TabLayout
android:id="@+id/indicator"
Expand Down

0 comments on commit 8bd1b69

Please sign in to comment.