Skip to content

Commit

Permalink
Use toast extension method from Android-ktx
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhanniballake committed Apr 4, 2018
1 parent 6148b42 commit aeff066
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 37 deletions.
Expand Up @@ -34,9 +34,9 @@ import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import android.widget.TextView
import android.widget.Toast
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.widget.toast
import com.google.android.apps.muzei.api.MuzeiArtSource
import com.google.android.apps.muzei.api.MuzeiContract
import com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver
Expand Down Expand Up @@ -144,8 +144,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
} catch (e: RuntimeException) {
// Catch ActivityNotFoundException, SecurityException,
// and FileUriExposedException
Toast.makeText(context, R.string.error_view_details,
Toast.LENGTH_SHORT).show()
requireContext().toast(R.string.error_view_details)
Log.e(TAG, "Error viewing artwork details.", e)
}
}
Expand Down
Expand Up @@ -26,6 +26,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.widget.toast

import com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment
import com.google.firebase.analytics.FirebaseAnalytics
Expand Down Expand Up @@ -67,8 +68,7 @@ class IntroFragment : Fragment() {
startActivity(Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
} catch (e2: ActivityNotFoundException) {
Toast.makeText(context, R.string.error_wallpaper_chooser,
Toast.LENGTH_LONG).show()
requireContext().toast(R.string.error_wallpaper_chooser, Toast.LENGTH_LONG)
}
}
}
Expand Down
Expand Up @@ -21,8 +21,8 @@ import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.core.widget.toast
import com.google.android.apps.muzei.single.SingleArtSource
import com.google.android.apps.muzei.sources.SourceManager
import com.google.android.apps.muzei.util.observeOnce
Expand All @@ -43,7 +43,7 @@ class PhotoSetAsTargetActivity : Activity() {
SingleArtSource.setArtwork(context, this).observeOnce { success ->
if (success == false) {
Log.e(TAG, "Unable to insert artwork for ${this@apply}")
Toast.makeText(context, R.string.set_as_wallpaper_failed, Toast.LENGTH_SHORT).show()
context.toast(R.string.set_as_wallpaper_failed)
finish()
return@observeOnce
}
Expand Down
Expand Up @@ -30,6 +30,7 @@ import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.support.annotation.RequiresApi
import android.widget.Toast
import androidx.core.widget.toast
import com.google.android.apps.muzei.MuzeiWallpaperService
import com.google.android.apps.muzei.api.MuzeiArtSource
import com.google.android.apps.muzei.room.MuzeiDatabase
Expand Down Expand Up @@ -123,8 +124,7 @@ class NextArtworkTileService : TileService(), LifecycleOwner {
startActivityAndCollapse(Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
} catch (e: ActivityNotFoundException) {
Toast.makeText(context, R.string.error_wallpaper_chooser,
Toast.LENGTH_LONG).show()
context.toast(R.string.error_wallpaper_chooser, Toast.LENGTH_LONG)
}
}
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ import android.view.ViewTreeObserver
import android.widget.TextView
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.core.widget.toast
import com.google.android.apps.muzei.api.MuzeiArtSource
import com.google.android.apps.muzei.notifications.NotificationSettingsDialogFragment
import com.google.android.apps.muzei.room.MuzeiDatabase
Expand Down Expand Up @@ -188,10 +189,9 @@ class ChooseSourceFragment : Fragment() {
preferPackageForIntent(playStoreIntent, PLAY_STORE_PACKAGE_NAME)
startActivity(playStoreIntent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(context,
R.string.play_store_not_found, Toast.LENGTH_LONG).show()
requireContext().toast(R.string.play_store_not_found, Toast.LENGTH_LONG)
} catch (e: SecurityException) {
Toast.makeText(context, R.string.play_store_not_found, Toast.LENGTH_LONG).show()
requireContext().toast(R.string.play_store_not_found, Toast.LENGTH_LONG)
}

return true
Expand Down
Expand Up @@ -36,6 +36,7 @@ import android.os.Build
import android.text.TextUtils
import android.util.Log
import android.widget.Toast
import androidx.core.widget.toast
import com.google.android.apps.muzei.api.MuzeiArtSource
import com.google.android.apps.muzei.api.internal.ProtocolConstants.ACTION_HANDLE_COMMAND
import com.google.android.apps.muzei.api.internal.ProtocolConstants.ACTION_SUBSCRIBE
Expand Down Expand Up @@ -132,15 +133,15 @@ class SourceManager(private val context: Context) : DefaultLifecycleObserver, Li
.putExtra(EXTRA_COMMAND_ID, id))
} catch (e: PackageManager.NameNotFoundException) {
Log.i(TAG, "Sending action + $id to $selectedSource failed; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
} catch (e: IllegalStateException) {
Log.i(TAG, "Sending action + $id to $selectedSource failed; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
} catch (e: SecurityException) {
Log.i(TAG, "Sending action + $id to $selectedSource failed; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
}
}
Expand Down Expand Up @@ -379,15 +380,15 @@ class SourceManager(private val context: Context) : DefaultLifecycleObserver, Li
.putExtra(EXTRA_TOKEN, selectedSource.flattenToShortString()))
} catch (e: PackageManager.NameNotFoundException) {
Log.i(TAG, "Selected source $selectedSource is no longer available; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
} catch (e: IllegalStateException) {
Log.i(TAG, "Selected source $selectedSource is no longer available; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
} catch (e: SecurityException) {
Log.i(TAG, "Selected source $selectedSource is no longer available; switching to default.", e)
Toast.makeText(context, R.string.source_unavailable, Toast.LENGTH_LONG).show()
context.toast(R.string.source_unavailable, Toast.LENGTH_LONG)
selectSource(context, FeaturedArtSource::class)
}
}
Expand Down
Expand Up @@ -24,6 +24,7 @@ import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat
import android.util.Log
import android.widget.Toast
import androidx.core.widget.toast
import com.google.android.apps.muzei.api.Artwork
import com.google.android.apps.muzei.api.MuzeiContract
import com.google.android.apps.muzei.api.RemoteMuzeiArtSource
Expand Down Expand Up @@ -136,9 +137,7 @@ class FeaturedArtSource : RemoteMuzeiArtSource(SOURCE_NAME) {
} ?: run {
Log.w(TAG, "No current artwork, can't share.")
Handler(Looper.getMainLooper()).post {
Toast.makeText(this,
R.string.featuredart_source_error_no_artwork_to_share,
Toast.LENGTH_SHORT).show()
toast(R.string.featuredart_source_error_no_artwork_to_share)
}
}
}
Expand Down Expand Up @@ -169,9 +168,7 @@ class FeaturedArtSource : RemoteMuzeiArtSource(SOURCE_NAME) {
}

Handler(Looper.getMainLooper()).post {
Toast.makeText(this@FeaturedArtSource,
"Next update time: $nextUpdateTime",
Toast.LENGTH_LONG).show()
toast("Next update time: $nextUpdateTime", Toast.LENGTH_LONG)
}
}
}
Expand Down
Expand Up @@ -6,7 +6,7 @@ import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v4.app.ShareCompat
import android.util.Log
import android.widget.Toast
import androidx.core.widget.toast
import com.google.android.apps.muzei.util.observeOnce

/**
Expand Down Expand Up @@ -65,14 +65,13 @@ class GalleryAddPhotosActivity : Activity() {

private fun updateCount() {
if (successCount + failureCount == streamCount) {
val message = if (failureCount == 0) {
toast(if (failureCount == 0) {
resources.getQuantityString(R.plurals.gallery_add_photos_success,
successCount, successCount)
} else {
resources.getQuantityString(R.plurals.gallery_add_photos_failure,
failureCount, failureCount, streamCount)
}
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
})
finish()
}
}
Expand Down
Expand Up @@ -69,6 +69,7 @@ import android.widget.Toast
import android.widget.ViewAnimator
import androidx.core.content.edit
import androidx.core.database.getStringOrNull
import androidx.core.widget.toast
import com.google.android.apps.muzei.util.MultiSelectionController
import com.google.android.apps.muzei.util.observe
import com.google.android.apps.muzei.util.observeOnce
Expand Down Expand Up @@ -268,8 +269,7 @@ class GallerySettingsActivity : AppCompatActivity(), Observer<PagedList<ChosenPh
startActivityForResult(intent, REQUEST_CHOOSE_FOLDER)
val preferences = getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE)
if (preferences.getBoolean(SHOW_INTERNAL_STORAGE_MESSAGE, true)) {
Toast.makeText(this, R.string.gallery_internal_storage_message,
Toast.LENGTH_LONG).show()
toast(R.string.gallery_internal_storage_message, Toast.LENGTH_LONG)
}
} catch (e: ActivityNotFoundException) {
Snackbar.make(photoGridView, R.string.gallery_add_folder_error,
Expand Down Expand Up @@ -434,9 +434,7 @@ class GallerySettingsActivity : AppCompatActivity(), Observer<PagedList<ChosenPh
Intent(this, GalleryArtSource::class.java)
.setAction(GalleryArtSource.ACTION_PUBLISH_NEXT_GALLERY_ITEM)
.putExtra(GalleryArtSource.EXTRA_FORCE_URI, selectedUri))
Toast.makeText(this,
R.string.gallery_temporary_force_image,
Toast.LENGTH_SHORT).show()
toast(R.string.gallery_temporary_force_image)
}
multiSelectionController.reset(true)
return@setOnMenuItemClickListener true
Expand Down
Expand Up @@ -34,8 +34,8 @@ import android.support.v4.app.NotificationCompat
import android.support.v4.content.ContextCompat
import android.support.wearable.activity.ConfirmationActivity
import android.util.Log
import android.widget.Toast
import androidx.core.content.edit
import androidx.core.widget.toast
import com.google.android.gms.tasks.Tasks
import com.google.android.gms.wearable.CapabilityClient
import com.google.android.gms.wearable.CapabilityInfo
Expand Down Expand Up @@ -207,8 +207,7 @@ class ActivateMuzeiIntentService : IntentService(TAG) {
putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true)
}
} else {
Toast.makeText(this@ActivateMuzeiIntentService,
R.string.activate_install_failed, Toast.LENGTH_SHORT).show()
toast(R.string.activate_install_failed)
}
}
})
Expand All @@ -228,7 +227,7 @@ class ActivateMuzeiIntentService : IntentService(TAG) {
}

if (nodes.isEmpty()) {
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show()
toast(R.string.activate_failed)
} else {
FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null)
// Show the open on phone animation
Expand Down

0 comments on commit aeff066

Please sign in to comment.