mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-08 07:48:45 +01:00
added switch to turn on user notifications, close #27
twitter streaming is now complete, close #81
This commit is contained in:
parent
5fcfc78f46
commit
c45ee87085
@ -63,6 +63,7 @@ import android.view.*
|
|||||||
import android.view.View.OnClickListener
|
import android.view.View.OnClickListener
|
||||||
import android.view.View.OnTouchListener
|
import android.view.View.OnTouchListener
|
||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
|
import android.widget.Toast
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.squareup.otto.Subscribe
|
import com.squareup.otto.Subscribe
|
||||||
import edu.tsinghua.hotmobi.HotMobiLogger
|
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.mute_user, !isMyself && isTwitter)
|
||||||
MenuUtils.setItemAvailability(menu, R.id.muted_users, 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.report_spam, !isMyself && isTwitter)
|
||||||
|
MenuUtils.setItemAvailability(menu, R.id.enable_notifications, !isMyself && isTwitter)
|
||||||
MenuUtils.setItemAvailability(menu, R.id.enable_retweets, !isMyself && isTwitter)
|
MenuUtils.setItemAvailability(menu, R.id.enable_retweets, !isMyself && isTwitter)
|
||||||
|
|
||||||
val userRelationship = relationship
|
val userRelationship = relationship
|
||||||
@ -847,14 +849,9 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
ActionIconDrawable.setMenuHighlight(blockItem, TwidereMenuInfo(userRelationship.blocking))
|
ActionIconDrawable.setMenuHighlight(blockItem, TwidereMenuInfo(userRelationship.blocking))
|
||||||
blockItem.setTitle(if (userRelationship.blocking) R.string.action_unblock else R.string.action_block)
|
blockItem.setTitle(if (userRelationship.blocking) R.string.action_unblock else R.string.action_block)
|
||||||
}
|
}
|
||||||
val muteItem = menu.findItem(R.id.mute_user)
|
menu.findItem(R.id.mute_user)?.isChecked = userRelationship.muting
|
||||||
if (muteItem != null) {
|
menu.findItem(R.id.enable_retweets)?.isChecked = userRelationship.retweet_enabled
|
||||||
muteItem.isChecked = userRelationship.muting
|
menu.findItem(R.id.enable_notifications)?.isChecked = userRelationship.notifications_enabled
|
||||||
}
|
|
||||||
val wantRetweetsItem = menu.findItem(R.id.enable_retweets)
|
|
||||||
if (wantRetweetsItem != null) {
|
|
||||||
wantRetweetsItem.isChecked = userRelationship.retweet_enabled
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MenuUtils.setItemAvailability(menu, R.id.send_direct_message, false)
|
MenuUtils.setItemAvailability(menu, R.id.send_direct_message, false)
|
||||||
@ -1028,6 +1025,18 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
item.isChecked = newState
|
item.isChecked = newState
|
||||||
return true
|
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 -> {
|
R.id.muted_users -> {
|
||||||
IntentUtils.openMutesUsers(activity, user.account_key)
|
IntentUtils.openMutesUsers(activity, user.account_key)
|
||||||
return true
|
return true
|
||||||
|
@ -34,7 +34,7 @@ import org.mariotaku.twidere.util.content.ContentResolverUtils
|
|||||||
object ParcelableRelationshipUtils {
|
object ParcelableRelationshipUtils {
|
||||||
|
|
||||||
fun create(accountKey: UserKey, userKey: UserKey, relationship: Relationship?,
|
fun create(accountKey: UserKey, userKey: UserKey, relationship: Relationship?,
|
||||||
filtering: Boolean): ParcelableRelationship {
|
filtering: Boolean = false): ParcelableRelationship {
|
||||||
val obj = ParcelableRelationship()
|
val obj = ParcelableRelationship()
|
||||||
obj.account_key = accountKey
|
obj.account_key = accountKey
|
||||||
obj.user_key = userKey
|
obj.user_key = userKey
|
||||||
|
@ -39,6 +39,7 @@ import org.mariotaku.twidere.constant.SharedPreferenceConstants
|
|||||||
import org.mariotaku.twidere.constant.nameFirstKey
|
import org.mariotaku.twidere.constant.nameFirstKey
|
||||||
import org.mariotaku.twidere.model.*
|
import org.mariotaku.twidere.model.*
|
||||||
import org.mariotaku.twidere.model.event.*
|
import org.mariotaku.twidere.model.event.*
|
||||||
|
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
|
||||||
import org.mariotaku.twidere.model.util.ParcelableUserListUtils
|
import org.mariotaku.twidere.model.util.ParcelableUserListUtils
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||||
import org.mariotaku.twidere.task.*
|
import org.mariotaku.twidere.task.*
|
||||||
@ -326,11 +327,12 @@ class AsyncTwitterWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateFriendship(accountKey: UserKey, userKey: UserKey, update: FriendshipUpdate) {
|
fun updateFriendship(accountKey: UserKey, userKey: UserKey, update: FriendshipUpdate) {
|
||||||
TaskStarter.execute(object : ExceptionHandlingAbstractTask<Any, Relationship, Exception, Any>(context) {
|
TaskStarter.execute(object : ExceptionHandlingAbstractTask<Any?, Relationship, Exception, Any>(context) {
|
||||||
override fun onExecute(params: Any): Relationship {
|
override fun onExecute(params: Any?): Relationship {
|
||||||
val microBlog = MicroBlogAPIFactory.getInstance(context, accountKey)
|
val microBlog = MicroBlogAPIFactory.getInstance(context, accountKey)
|
||||||
?: throw MicroBlogException("No account")
|
?: throw MicroBlogException("No account")
|
||||||
val relationship = microBlog.updateFriendship(userKey.id, update)
|
val relationship = microBlog.updateFriendship(userKey.id, update)
|
||||||
|
val cr = context.contentResolver
|
||||||
if (!relationship.isSourceWantRetweetsFromTarget) {
|
if (!relationship.isSourceWantRetweetsFromTarget) {
|
||||||
// TODO remove cached retweets
|
// TODO remove cached retweets
|
||||||
val where = Expression.and(
|
val where = Expression.and(
|
||||||
@ -338,8 +340,11 @@ class AsyncTwitterWrapper(
|
|||||||
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)
|
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)
|
||||||
)
|
)
|
||||||
val selectionArgs = arrayOf(accountKey.toString(), userKey.toString())
|
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
|
return relationship
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,12 @@
|
|||||||
android:icon="@drawable/ic_action_time"
|
android:icon="@drawable/ic_action_time"
|
||||||
android:title="@string/scheduled_statuses"
|
android:title="@string/scheduled_statuses"
|
||||||
android:visible="false"/>
|
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
|
<item
|
||||||
android:id="@id/enable_retweets"
|
android:id="@id/enable_retweets"
|
||||||
android:checkable="true"
|
android:checkable="true"
|
||||||
|
@ -342,6 +342,7 @@
|
|||||||
|
|
||||||
<string name="empty_content">Empty content</string>
|
<string name="empty_content">Empty content</string>
|
||||||
|
|
||||||
|
<string name="enable_notifications">Enable notifications</string>
|
||||||
<string name="enable_retweets">Enable retweets</string>
|
<string name="enable_retweets">Enable retweets</string>
|
||||||
<string name="enable_streaming">Enable streaming</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_permission">Account permission is required</string>
|
||||||
<string name="message_toast_no_account_selected">No account selected</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_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_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_profile_banner_image_updated">Profile banner image updated</string>
|
||||||
<string name="message_toast_retweet_cancelled">Retweet cancelled</string>
|
<string name="message_toast_retweet_cancelled">Retweet cancelled</string>
|
||||||
@ -713,8 +715,8 @@
|
|||||||
<string name="notification_ringtone">Ringtone</string>
|
<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">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_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_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_home">Home</string>
|
||||||
<string name="notification_type_interactions">Interactions</string>
|
<string name="notification_type_interactions">Interactions</string>
|
||||||
<string name="notification_type_messages">Messages</string>
|
<string name="notification_type_messages">Messages</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user