1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01:00

Feature/ringtone selector (#200)

* Update changelog

* Create and test ringtone selector

* Update changelog

* Update text
This commit is contained in:
Allan Wang 2017-08-19 23:18:47 -07:00 committed by GitHub
parent 8c178bd82d
commit 17b2b7a21b
14 changed files with 121 additions and 34 deletions

View File

@ -3,6 +3,8 @@ package com.pitchedapps.frost.activities
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -32,12 +34,39 @@ class SettingsActivity : KPrefActivity(), FrostBilling by IABSettings() {
var resultFlag = Activity.RESULT_CANCELED
companion object {
private const val REQUEST_RINGTONE = 0b10111 shl 5
const val REQUEST_NOTIFICATION_RINGTONE = REQUEST_RINGTONE or 1
const val REQUEST_MESSAGE_RINGTONE = REQUEST_RINGTONE or 2
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (fetchRingtone(requestCode, resultCode, data)) return
if (!onActivityResultBilling(requestCode, resultCode, data))
super.onActivityResult(requestCode, resultCode, data)
reloadList()
}
/**
* Fetch ringtone and save uri
* Returns [true] if consumed, [false] otherwise
*/
private fun fetchRingtone(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
if (requestCode and REQUEST_RINGTONE != REQUEST_RINGTONE || resultCode != Activity.RESULT_OK) return false
val uri: String = data?.getParcelableExtra<Uri>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)?.toString() ?: ""
when (requestCode) {
REQUEST_NOTIFICATION_RINGTONE -> {
Prefs.notificationRingtone = uri
reloadByTitle(R.string.notification_ringtone)
}
REQUEST_MESSAGE_RINGTONE -> {
Prefs.messageRingtone = uri
reloadByTitle(R.string.message_ringtone)
}
}
return true
}
override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = {
textColor = { Prefs.textColor }
accentColor = { Prefs.accentColor }

View File

@ -13,7 +13,6 @@ import android.webkit.WebChromeClient
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.swipe.kauSwipeOnCreate
import ca.allanwang.kau.swipe.kauSwipeOnDestroy
import ca.allanwang.kau.swipe.kauSwipeOnPostCreate
import ca.allanwang.kau.utils.*
import com.mikepenz.community_material_typeface_library.CommunityMaterial
import com.mikepenz.google_material_typeface_library.GoogleMaterial

View File

@ -23,7 +23,7 @@ enum class MainActivityLayout(
{ Prefs.textColor });
companion object {
val values = MainActivityLayout.values() //save one instance
val values = values() //save one instance
operator fun invoke(index: Int) = values[index]
}
}

View File

@ -8,8 +8,8 @@ import android.view.View
import android.view.ViewGroup
import ca.allanwang.kau.utils.withArguments
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.enums.FeedSort
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.web.FrostWebView
import com.pitchedapps.frost.web.FrostWebViewCore

View File

@ -6,8 +6,8 @@ import ca.allanwang.kau.utils.bindViewResettable
import ca.allanwang.kau.utils.scaleXY
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.IntroActivity
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.utils.Prefs
/**
* Created by Allan Wang on 2017-07-28.

View File

@ -34,27 +34,34 @@ import org.jetbrains.anko.runOnUiThread
* Logic for build notifications, scheduling notifications, and showing notifications
*/
val Context.frostNotification: NotificationCompat.Builder
get() = frostNotification()
/**
* Wrap the default builder with our icon and accent color
*/
val Context.frostNotification: NotificationCompat.Builder
get() = NotificationCompat.Builder(this, BuildConfig.APPLICATION_ID).apply {
setSmallIcon(R.drawable.frost_f_24)
setAutoCancel(true)
color = color(R.color.frost_notification_accent)
}
/**
* Assign global changes to the notification after it is built
*/
@Suppress("DEPRECATION")
//The update feature is for Android O and seems to still be in beta
fun Notification.frostConfig() = apply {
fun Context.frostNotification(ringtone: String = Prefs.notificationRingtone): NotificationCompat.Builder
= NotificationCompat.Builder(this, BuildConfig.APPLICATION_ID).apply {
setSmallIcon(R.drawable.frost_f_24)
setAutoCancel(true)
color = color(R.color.frost_notification_accent)
var defaults = 0
if (Prefs.notificationVibrate) defaults = defaults or Notification.DEFAULT_VIBRATE
if (Prefs.notificationSound) defaults = defaults or Notification.DEFAULT_SOUND
if (Prefs.notificationSound) {
if (ringtone.isNotBlank()) setSound(Uri.parse(ringtone))
else defaults = defaults or Notification.DEFAULT_SOUND
}
if (Prefs.notificationLights) defaults = defaults or Notification.DEFAULT_LIGHTS
setDefaults(defaults)
}
val NotificationCompat.Builder.quiet
get() = apply { setDefaults(0) }
val NotificationCompat.Builder.messageRingtone
get() = apply { }
val NotificationCompat.Builder.withBigText: NotificationCompat.BigTextStyle
get() = NotificationCompat.BigTextStyle(this)
@ -72,7 +79,7 @@ class FrostNotificationTarget(val context: Context,
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>) {
builder.setLargeIcon(resource)
NotificationManagerCompat.from(context).notify(notifTag, notifId, builder.withBigText.build().frostConfig())
NotificationManagerCompat.from(context).notify(notifTag, notifId, builder.withBigText.build())
}
}
@ -99,7 +106,8 @@ data class NotificationContent(val data: CookieModel,
intent.putExtra(ARG_USER_ID, data.id)
val group = "${groupPrefix}_${data.id}"
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
val notifBuilder = context.frostNotification
val ringtone = if (groupPrefix == FROST_MESSAGE_NOTIFICATION_GROUP) Prefs.messageRingtone else Prefs.notificationRingtone
val notifBuilder = context.frostNotification(ringtone)
.setContentTitle(title ?: context.string(R.string.frost_name))
.setContentText(text)
.setContentIntent(pendingIntent)
@ -109,7 +117,7 @@ data class NotificationContent(val data: CookieModel,
if (timestamp != -1L) notifBuilder.setWhen(timestamp * 1000)
L.v("Notif load", this.toString())
NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.withBigText.build().frostConfig())
NotificationManagerCompat.from(context).notify(group, notifId, notifBuilder.withBigText.build())
if (profileUrl.isNotBlank()) {
context.runOnUiThread {

View File

@ -233,7 +233,7 @@ class NotificationService : JobService() {
val notifBuilder = frostNotification
.setContentTitle(string(R.string.frost_name))
.setContentText(text)
NotificationManagerCompat.from(this).notify(999, notifBuilder.build().frostConfig())
NotificationManagerCompat.from(this).notify(999, notifBuilder.build())
}
private fun summaryNotification(userId: Long, count: Int, contentRes: Int, pendingUrl: String, groupPrefix: String) {
@ -250,7 +250,7 @@ class NotificationService : JobService() {
.setContentIntent(pendingIntent)
.setCategory(Notification.CATEGORY_SOCIAL)
NotificationManagerCompat.from(this).notify("${groupPrefix}_$userId", userId.toInt(), notifBuilder.build().frostConfig())
NotificationManagerCompat.from(this).notify("${groupPrefix}_$userId", userId.toInt(), notifBuilder.build())
}
}

View File

@ -1,7 +1,12 @@
package com.pitchedapps.frost.settings
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
import ca.allanwang.kau.kpref.activity.items.KPrefText
import ca.allanwang.kau.utils.minuteToText
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.services.fetchNotifications
@ -11,6 +16,7 @@ import com.pitchedapps.frost.utils.frostSnackbar
import com.pitchedapps.frost.utils.materialDialogThemed
import com.pitchedapps.frost.views.Keywords
/**
* Created by Allan Wang on 2017-06-29.
*/
@ -59,7 +65,36 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
descRes = R.string.notification_messages_desc
}
checkbox(R.string.notification_sound, { Prefs.notificationSound }, { Prefs.notificationSound = it })
checkbox(R.string.notification_sound, { Prefs.notificationSound }, { Prefs.notificationSound = it; reloadByTitle(R.string.notification_ringtone, R.string.message_ringtone) })
fun KPrefText.KPrefTextContract<String>.ringtone(code: Int) {
enabler = { Prefs.notificationSound }
textGetter = {
if (it.isBlank()) string(R.string.kau_default)
else RingtoneManager.getRingtone(this@getNotificationPrefs, Uri.parse(it)).getTitle(this@getNotificationPrefs)
}
onClick = {
_, _, item ->
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, string(R.string.select_ringtone))
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
if (item.pref.isNotBlank())
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(item.pref))
}
startActivityForResult(intent, code)
true
}
}
text(R.string.notification_ringtone, { Prefs.notificationRingtone }, { Prefs.notificationRingtone = it }) {
ringtone(SettingsActivity.REQUEST_NOTIFICATION_RINGTONE)
}
text(R.string.message_ringtone, { Prefs.messageRingtone }, { Prefs.messageRingtone = it }) {
ringtone(SettingsActivity.REQUEST_MESSAGE_RINGTONE)
}
checkbox(R.string.notification_vibrate, { Prefs.notificationVibrate }, { Prefs.notificationVibrate = it })
@ -75,5 +110,4 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
}
}
}

View File

@ -13,9 +13,9 @@ import ca.allanwang.kau.utils.copyFromInputStream
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.services.frostConfig
import com.pitchedapps.frost.services.frostNotification
import com.pitchedapps.frost.services.getNotificationPendingCancelIntent
import com.pitchedapps.frost.services.quiet
import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
@ -66,7 +66,7 @@ private fun AnkoAsyncContext<Context>.frostDownloadImpl(url: String, type: Downl
val notifId = Math.abs(url.hashCode() + System.currentTimeMillis().toInt())
var notifBuilderAttempt: NotificationCompat.Builder? = null
weakRef.get()?.apply {
notifBuilderAttempt = frostNotification
notifBuilderAttempt = frostNotification.quiet
.setContentTitle(string(type.downloadingRes))
.setCategory(Notification.CATEGORY_PROGRESS)
.setWhen(System.currentTimeMillis())
@ -133,7 +133,7 @@ private fun OkHttpClient.cancel(url: String) {
private fun NotificationCompat.Builder.show(weakRef: WeakReference<Context>, notifId: Int) {
val c = weakRef.get() ?: return
NotificationManagerCompat.from(c).notify(DOWNLOAD_GROUP, notifId, build().frostConfig())
NotificationManagerCompat.from(c).notify(DOWNLOAD_GROUP, notifId, build())
}
private class ProgressResponseBody(

View File

@ -7,9 +7,9 @@ import ca.allanwang.kau.kpref.StringSet
import ca.allanwang.kau.kpref.kpref
import ca.allanwang.kau.utils.isColorVisibleOn
import com.pitchedapps.frost.enums.FACEBOOK_BLUE
import com.pitchedapps.frost.enums.FeedSort
import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.enums.FeedSort
import com.pitchedapps.frost.injectors.InjectorContract
/**
@ -104,6 +104,10 @@ object Prefs : KPref() {
var notificationSound: Boolean by kpref("notification_sound", true)
var notificationRingtone: String by kpref("notification_ringtone", "")
var messageRingtone: String by kpref("message_ringtone", "")
var notificationLights: Boolean by kpref("notification_lights", true)
var messageScrollToBottom: Boolean by kpref("message_scroll_to_bottom", false)

View File

@ -12,10 +12,15 @@
<string name="notification_messages">Enable message notifications</string>
<string name="notification_messages_desc">Get instant message notifications for your current account.</string>
<string name="notification_fetch_now">Fetch Notifications Now</string>
<string name="notification_fetch_now_desc">Trigger the notification fetcher one time.</string>
<string name="notification_fetch_now_desc">Trigger the notification fetcher once. Note that fetching instant messages takes time.</string>
<string name="notification_fetch_success">Fetching Notifications…</string>
<string name="notification_fetch_fail">Couldn\'t fetch notifications</string>
<string name="notification_sound">Notification sound</string>
<string name="notification_ringtone">Notification Ringtone</string>
<string name="message_ringtone">Message Ringtone</string>
<string name="select_ringtone">Selet Ringtone</string>
<string name="notification_vibrate">Notification vibration</string>
<string name="notification_lights">Notification lights</string>

View File

@ -2,7 +2,7 @@
<string name="appearance">Appearance</string>
<string name="appearance_desc">Theme, Items to display, etc</string>
<string name="notifications_desc">Frequency, filters, etc</string>
<string name="notifications_desc">Frequency, filters, ringtones, etc</string>
<string name="newsfeed">News Feed</string>
<string name="newsfeed_desc">Define what items appear in the newsfeed</string>

View File

@ -11,7 +11,13 @@
<!--<version title="Beta Updates" />-->
<version title="Beta Updates"/>
<item text="Update secondary background for transparent themes to be more visible." />
<item text="Fix url loading bug and add option to launch urls in default browser (behaviour setting)" />
<item text="Allow for bottom bar tabs (appearance setting)" />
<item text="Allow custom ringtones for notifications and messages (notification setting)" />
<item text="" />
<version title="v1.4.7"/>
<item text="Update secondary background for transparent themes to be more visible." />
<item text="Pressing enter when searching will launch the full search page" />
<item text="Add different backgrounds for news feed articles." />
<item text="Add option to get image/video from default camera or gallery app." />
@ -19,8 +25,6 @@
<item text="Remove error dialog for IAB. It will now depend solely on the google services dialogs." />
<item text="Fix loading issue for old conversations" />
<item text="Add debugger for failed image activities" />
<item text="" />
<item text="" />
<version title="v1.4.5"/>
<item text="Create more robust IM notification fetcher with a timeout" />

View File

@ -1,6 +1,10 @@
# Changelog
## Beta Updates
* Fix url loading bug and add option to launch urls in default browser (behaviour setting)
* Allow for bottom bar tabs (appearance setting)
## v1.4.7
* Update secondary background for transparent themes to be more visible.
* Pressing enter when searching will launch the full search page
* Add different backgrounds for news feed articles.