added switch to turn on user notifications, close #27

twitter streaming is now complete, close #81
This commit is contained in:
Mariotaku Lee 2017-03-18 17:35:32 +08:00
parent 5fcfc78f46
commit c45ee87085
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 35 additions and 13 deletions

View File

@ -63,6 +63,7 @@ import android.view.*
import android.view.View.OnClickListener
import android.view.View.OnTouchListener
import android.view.animation.AnimationUtils
import android.widget.Toast
import com.bumptech.glide.Glide
import com.squareup.otto.Subscribe
import edu.tsinghua.hotmobi.HotMobiLogger
@ -828,6 +829,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
MenuUtils.setItemAvailability(menu, R.id.mute_user, !isMyself && isTwitter)
MenuUtils.setItemAvailability(menu, R.id.muted_users, isMyself && isTwitter)
MenuUtils.setItemAvailability(menu, R.id.report_spam, !isMyself && isTwitter)
MenuUtils.setItemAvailability(menu, R.id.enable_notifications, !isMyself && isTwitter)
MenuUtils.setItemAvailability(menu, R.id.enable_retweets, !isMyself && isTwitter)
val userRelationship = relationship
@ -847,14 +849,9 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
ActionIconDrawable.setMenuHighlight(blockItem, TwidereMenuInfo(userRelationship.blocking))
blockItem.setTitle(if (userRelationship.blocking) R.string.action_unblock else R.string.action_block)
}
val muteItem = menu.findItem(R.id.mute_user)
if (muteItem != null) {
muteItem.isChecked = userRelationship.muting
}
val wantRetweetsItem = menu.findItem(R.id.enable_retweets)
if (wantRetweetsItem != null) {
wantRetweetsItem.isChecked = userRelationship.retweet_enabled
}
menu.findItem(R.id.mute_user)?.isChecked = userRelationship.muting
menu.findItem(R.id.enable_retweets)?.isChecked = userRelationship.retweet_enabled
menu.findItem(R.id.enable_notifications)?.isChecked = userRelationship.notifications_enabled
}
} else {
MenuUtils.setItemAvailability(menu, R.id.send_direct_message, false)
@ -1028,6 +1025,18 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
item.isChecked = newState
return true
}
R.id.enable_notifications -> {
val newState = !item.isChecked
if (newState) {
Toast.makeText(context, R.string.message_toast_notification_enabled_hint,
Toast.LENGTH_SHORT).show()
}
val update = FriendshipUpdate()
update.deviceNotifications(newState)
twitter.updateFriendship(user.account_key, user.key, update)
item.isChecked = newState
return true
}
R.id.muted_users -> {
IntentUtils.openMutesUsers(activity, user.account_key)
return true

View File

@ -34,7 +34,7 @@ import org.mariotaku.twidere.util.content.ContentResolverUtils
object ParcelableRelationshipUtils {
fun create(accountKey: UserKey, userKey: UserKey, relationship: Relationship?,
filtering: Boolean): ParcelableRelationship {
filtering: Boolean = false): ParcelableRelationship {
val obj = ParcelableRelationship()
obj.account_key = accountKey
obj.user_key = userKey

View File

@ -39,6 +39,7 @@ import org.mariotaku.twidere.constant.SharedPreferenceConstants
import org.mariotaku.twidere.constant.nameFirstKey
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.event.*
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
import org.mariotaku.twidere.model.util.ParcelableUserListUtils
import org.mariotaku.twidere.provider.TwidereDataStore.*
import org.mariotaku.twidere.task.*
@ -326,11 +327,12 @@ class AsyncTwitterWrapper(
}
fun updateFriendship(accountKey: UserKey, userKey: UserKey, update: FriendshipUpdate) {
TaskStarter.execute(object : ExceptionHandlingAbstractTask<Any, Relationship, Exception, Any>(context) {
override fun onExecute(params: Any): Relationship {
TaskStarter.execute(object : ExceptionHandlingAbstractTask<Any?, Relationship, Exception, Any>(context) {
override fun onExecute(params: Any?): Relationship {
val microBlog = MicroBlogAPIFactory.getInstance(context, accountKey)
?: throw MicroBlogException("No account")
val relationship = microBlog.updateFriendship(userKey.id, update)
val cr = context.contentResolver
if (!relationship.isSourceWantRetweetsFromTarget) {
// TODO remove cached retweets
val where = Expression.and(
@ -338,8 +340,11 @@ class AsyncTwitterWrapper(
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)
)
val selectionArgs = arrayOf(accountKey.toString(), userKey.toString())
context.contentResolver.delete(Statuses.CONTENT_URI, where.sql, selectionArgs)
cr.delete(Statuses.CONTENT_URI, where.sql, selectionArgs)
}
ParcelableRelationshipUtils.insert(cr, listOf(ParcelableRelationshipUtils
.create(accountKey, userKey, relationship)))
return relationship
}

View File

@ -42,6 +42,12 @@
android:icon="@drawable/ic_action_time"
android:title="@string/scheduled_statuses"
android:visible="false"/>
<item
android:id="@+id/enable_notifications"
android:checkable="true"
android:checked="false"
android:icon="@drawable/ic_action_notification"
android:title="@string/enable_notifications"/>
<item
android:id="@id/enable_retweets"
android:checkable="true"

View File

@ -342,6 +342,7 @@
<string name="empty_content">Empty content</string>
<string name="enable_notifications">Enable notifications</string>
<string name="enable_retweets">Enable retweets</string>
<string name="enable_streaming">Enable streaming</string>
@ -632,6 +633,7 @@
<string name="message_toast_no_account_permission">Account permission is required</string>
<string name="message_toast_no_account_selected">No account selected</string>
<string name="message_toast_no_user_selected">No user selected</string>
<string name="message_toast_notification_enabled_hint">Only available when streaming is on, and not 100% reliable.</string>
<string name="message_toast_press_again_to_close">Press again to close</string>
<string name="message_toast_profile_banner_image_updated">Profile banner image updated</string>
<string name="message_toast_retweet_cancelled">Retweet cancelled</string>
@ -713,8 +715,8 @@
<string name="notification_ringtone">Ringtone</string>
<string name="notification_status">New tweet by <xliff:g id="user">%s</xliff:g></string>
<string name="notification_status_multiple">New Tweet by <xliff:g id="user">%1$s</xliff:g> and <xliff:g id="count">%2$d</xliff:g> others</string>
<string name="notification_title_new_status_by_user">New tweet by <xliff:g id="user">%1$s</xliff:g></string>
<string name="notification_title_new_retweet_by_user"><xliff:g id="user">%1$s</xliff:g> retweeted</string>
<string name="notification_title_new_status_by_user">New tweet by <xliff:g id="user">%1$s</xliff:g></string>
<string name="notification_type_home">Home</string>
<string name="notification_type_interactions">Interactions</string>
<string name="notification_type_messages">Messages</string>