Skip to content

Commit

Permalink
fix NPE on MainActivity#onClick (reported on Telegram)
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Aug 20, 2023
1 parent e69077c commit acdb79d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public void onClick(View v) {
.add(
R.id.constraintLayout,
CustomiseFragment.newInstance(
allQuotesList.get(viewPager.getCurrentItem())),
allQuotesList != null
? allQuotesList.get(viewPager.getCurrentItem())
: Utils.Companion.getSampleQuote()),
null)
.addToBackStack(null)
.commit();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/phone/vishnu/quotes/helper/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ package phone.vishnu.quotes.helper
import android.content.Context
import android.content.res.Resources
import android.util.DisplayMetrics
import phone.vishnu.quotes.model.Quote
import kotlin.math.roundToInt

class Utils {

companion object {

val sampleQuote: Quote = Quote(
"Twenty years from now you will be more disappointed by the things that you didn’t do than by the ones you did do, so throw off the bowlines, sail away from safe harbor, catch the trade winds in your sails. Explore, Dream, Discover",
"Mark Twain",
)

fun DPtoPX(context: Context, DP: Int): Int {
return (DP * (context.resources.displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)).roundToInt()
}
Expand Down

0 comments on commit acdb79d

Please sign in to comment.