aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-10-29 13:17:31 -0400
committerGitHub <noreply@github.com>2017-10-29 13:17:31 -0400
commitd82a9b9e2965b3e674aa0e654cfca55398a508a7 (patch)
tree944a46eac64e7a2595f6ad7b438cfdce6ed91b14
parentca12899e10da6e900499b7c4b99cc700cd5b9176 (diff)
downloadfrost-d82a9b9e2965b3e674aa0e654cfca55398a508a7.tar.gz
frost-d82a9b9e2965b3e674aa0e654cfca55398a508a7.tar.bz2
frost-d82a9b9e2965b3e674aa0e654cfca55398a508a7.zip
fix/weakRef (#452)
* Add activity context wrapper for images * Remove unused receiver * Add action check * Add image activity logging * Do not log image url
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt34
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/UpdateReceiver.kt2
4 files changed, 5 insertions, 41 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2a23ea02..5ebb2118 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -156,9 +156,6 @@
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
- <receiver
- android:name=".services.NotificationReceiver"
- android:enabled="true" />
<provider
android:name="android.support.v4.content.FileProvider"
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
index e32a2ea9..0a713649 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
@@ -31,8 +31,8 @@ import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.*
import com.sothree.slidinguppanel.SlidingUpPanelLayout
+import org.jetbrains.anko.activityUiThreadWithContext
import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.uiThread
import java.io.File
import java.io.IOException
@@ -76,7 +76,7 @@ class ImageActivity : KauBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- L.i("Displaying image $imageUrl")
+ L.i("Displaying image", imageUrl)
val layout = if (!text.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless
setContentView(layout)
container.setBackgroundColor(Prefs.bgColor.withMinAlpha(222))
@@ -179,7 +179,7 @@ class ImageActivity : KauBaseActivity() {
success = false
} finally {
L.d("Download image async finished: $success")
- uiThread {
+ activityUiThreadWithContext {
val text = if (success) R.string.image_download_success else R.string.image_download_fail
frostSnackbar(text)
if (success) fabAction = FabStates.SHARE
@@ -199,6 +199,7 @@ class ImageActivity : KauBaseActivity() {
override fun onDestroy() {
deleteTempFile()
+ if (!BuildConfig.DEBUG) L.d("Closing $localClassName")
super.onDestroy()
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt
deleted file mode 100644
index c903ff72..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationReceiver.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.pitchedapps.frost.services
-
-import android.app.PendingIntent
-import android.content.BroadcastReceiver
-import android.content.Context
-import android.content.Intent
-import android.support.v4.app.NotificationManagerCompat
-import com.pitchedapps.frost.utils.L
-
-/**
- * Created by Allan Wang on 2017-08-04.
- *
- * Cancels a notification
- */
-private const val NOTIF_TAG_TO_CANCEL = "notif_tag_to_cancel"
-private const val NOTIF_ID_TO_CANCEL = "notif_id_to_cancel"
-
-class NotificationReceiver : BroadcastReceiver() {
- override fun onReceive(context: Context, intent: Intent) {
- L.d("NotificationReceiver triggered")
- val notifTag = intent.getStringExtra(NOTIF_TAG_TO_CANCEL)
- val notifId = intent.getIntExtra(NOTIF_ID_TO_CANCEL, -1)
- if (notifId != -1) {
- L.d("NotificationReceiver: Cancelling $notifTag $notifId")
- NotificationManagerCompat.from(context).cancel(notifTag, notifId)
- }
- }
-}
-
-fun Context.getNotificationPendingCancelIntent(tag: String?, notifId: Int): PendingIntent {
- val cancelIntent = Intent(this, NotificationReceiver::class.java)
- .putExtra(NOTIF_TAG_TO_CANCEL, tag).putExtra(NOTIF_ID_TO_CANCEL, notifId)
- return PendingIntent.getBroadcast(this, 0, cancelIntent, 0)
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateReceiver.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateReceiver.kt
index 9e53889e..989ac127 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateReceiver.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateReceiver.kt
@@ -13,8 +13,8 @@ import com.pitchedapps.frost.utils.Prefs
*/
class UpdateReceiver : BroadcastReceiver() {
- //todo check action warning
override fun onReceive(context: Context, intent: Intent) {
+ if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return
L.d("Frost has updated")
context.scheduleNotifications(Prefs.notificationFreq) //Update notifications
}