forked from devmil/muzei-bingimageoftheday
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve image from `ContentProvider` rather than network. Rebuild missing cache by calling `ContentResolver.openFileDescriptor()` if needed. Also polish share intent and command names.
- Loading branch information
Showing
6 changed files
with
136 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/de/devmil/common/utils/BroadcastReceiverExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* From: https://github.com/romannurik/muzei/blob/d9899b5d35336d7fdfd6007b13506b249afa754e/extensions/src/main/java/com/google/android/apps/muzei/util/BroadcastReceiverExt.kt | ||
*/ | ||
|
||
package de.devmil.common.utils | ||
|
||
import android.content.BroadcastReceiver | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
|
||
fun BroadcastReceiver.goAsync( | ||
coroutineScope: CoroutineScope = GlobalScope, | ||
block: suspend () -> Unit | ||
) { | ||
val result = goAsync() | ||
coroutineScope.launch { | ||
try { | ||
block() | ||
} finally { | ||
// Always call finish(), even if the coroutineScope was cancelled | ||
result.finish() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* From: https://github.com/romannurik/muzei/blob/f929ba34a9376f5267bdaa0f8497f39671fcb1de/extensions/src/main/java/com/google/android/apps/muzei/util/ContextExt.kt | ||
*/ | ||
|
||
package de.devmil.common.utils | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
import androidx.annotation.StringRes | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* Creates and shows a [Toast] with the given [text] | ||
* | ||
* @param duration Toast duration, defaults to [Toast.LENGTH_SHORT] | ||
*/ | ||
fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) { | ||
Toast.makeText(this, text, duration).apply { show() } | ||
} | ||
|
||
/** | ||
* Creates and shows a [Toast] with text from a resource | ||
* | ||
* @param resId Resource id of the string resource to use | ||
* @param duration Toast duration, defaults to [Toast.LENGTH_SHORT] | ||
*/ | ||
fun Context.toast(@StringRes resId: Int, duration: Int = Toast.LENGTH_SHORT) { | ||
Toast.makeText(this, resId, duration).apply { show() } | ||
} | ||
|
||
fun Context.toastFromBackground( | ||
@StringRes resId: Int, | ||
duration: Int = Toast.LENGTH_SHORT | ||
) { | ||
GlobalScope.launch(Dispatchers.Main) { | ||
Toast.makeText(this@toastFromBackground, resId, duration).apply { show() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters