aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-10-08 00:08:48 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-10-08 00:53:24 +0900
commit16fbf18a9273a1acea81a0200d6988b04b253303 (patch)
tree242617e54ae48f5f16546c73b61f3a68d20615bb
parentf343789ef2ade0869b3dda5e5a0ccad3b0e4d480 (diff)
downloadSmileEssence-16fbf18a9273a1acea81a0200d6988b04b253303.tar.gz
listen simplify
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.kt67
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt22
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt45
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt52
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/data/Account.kt11
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/EntitySupport.kt3
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/RBinding.kt12
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/Tweet.kt5
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/User.kt92
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.kt20
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.kt9
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/util/BackgroundTask.kt5
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/util/BitmapURLTask.kt5
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/util/UIObservable.kt38
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/util/UIObserverBundle.kt27
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/Partials.kt44
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt31
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.kt2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.kt82
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt231
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt17
21 files changed, 249 insertions, 571 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.kt b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.kt
index b6d590f0..d52a7707 100644
--- a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.kt
@@ -36,13 +36,12 @@ import kotlinx.android.synthetic.main.list_item_simple_text.view.*
import net.lacolaco.smileessence.R
import net.lacolaco.smileessence.data.ExtractionWord
import net.lacolaco.smileessence.logging.Logger
-import net.lacolaco.smileessence.view.adapter.CustomListAdapter
import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter
import net.lacolaco.smileessence.view.dialog.EditTextDialogFragment
import java.util.ArrayList
-class EditExtractionActivity : Activity(), AbsListView.MultiChoiceModeListener {
+class EditExtractionActivity : Activity() {
private val adapter by lazy {
object : UnorderedCustomListAdapter<ExtractionWord>() {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
@@ -53,39 +52,6 @@ class EditExtractionActivity : Activity(), AbsListView.MultiChoiceModeListener {
}
}
- override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
- menu.clear()
- val inflater = mode.menuInflater
- inflater.inflate(R.menu.edit_list, menu)
- return true
- }
-
- override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
- return false
- }
-
- override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
- when (item.itemId) {
- R.id.menu_edit_list_delete -> {
- val checkedItems = listview_edit_list.checkedItemPositions
- for (i in adapter.count - 1 downTo -1 + 1) {
- if (checkedItems.get(i)) {
- val ew = adapter.getItem(i)
- adapter.remove(ew)
- ew.remove()
- }
- }
- adapter.update()
- }
- }
- mode.finish()
- return true
- }
-
- override fun onDestroyActionMode(mode: ActionMode) {}
-
- override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean) {}
-
override fun onCreate(savedInstanceState: Bundle?) {
Logger.debug("onCreate")
super.onCreate(savedInstanceState)
@@ -95,7 +61,36 @@ class EditExtractionActivity : Activity(), AbsListView.MultiChoiceModeListener {
adapter.update()
listview_edit_list.adapter = adapter
listview_edit_list.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL
- listview_edit_list.setMultiChoiceModeListener(this)
+ listview_edit_list.setMultiChoiceModeListener(object : AbsListView.MultiChoiceModeListener {
+ override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
+ when (item.itemId) {
+ R.id.menu_edit_list_delete -> {
+ val checkedItems = listview_edit_list.checkedItemPositions
+ for (i in adapter.count - 1 downTo -1 + 1) {
+ if (checkedItems.get(i)) {
+ val ew = adapter.getItem(i)
+ adapter.remove(ew)
+ ew.remove()
+ }
+ }
+ adapter.update()
+ }
+ }
+ mode.finish()
+ return true
+ }
+
+ override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
+ menu.clear()
+ val inflater = mode.menuInflater
+ inflater.inflate(R.menu.edit_list, menu)
+ return true
+ }
+
+ override fun onItemCheckedStateChanged(p0: ActionMode?, p1: Int, p2: Long, p3: Boolean) { }
+ override fun onPrepareActionMode(p0: ActionMode?, p1: Menu?) = false
+ override fun onDestroyActionMode(p0: ActionMode?) { }
+ })
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt
index b2c9e163..28a95a27 100644
--- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt
@@ -39,11 +39,9 @@ import de.keyboardsurfer.android.widget.crouton.Crouton
import kotlinx.android.synthetic.main.layout_main.*
import net.lacolaco.smileessence.*
import net.lacolaco.smileessence.data.ExtractionWord
-import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.logging.Logger
import net.lacolaco.smileessence.twitter.task.Users
import net.lacolaco.smileessence.util.BitmapURLTask
-import net.lacolaco.smileessence.util.UIObserverBundle
import net.lacolaco.smileessence.view.adapter.PageListAdapter
import net.lacolaco.smileessence.view.dialog.ConfirmDialogFragment
import net.lacolaco.smileessence.view.page.*
@@ -51,7 +49,6 @@ import org.jetbrains.anko.browse
import org.jetbrains.anko.startActivity;
class MainActivity : Activity(), ViewPager.OnPageChangeListener {
- private val currentUserBundle = UIObserverBundle()
val world: World by lazy {
val uri = intent.data ?: throw IllegalStateException("[BUG] data not set")
val userIdValue = uri.getQueryParameter("user_id") ?: throw IllegalStateException("[BUG] user_id not set")
@@ -111,6 +108,7 @@ class MainActivity : Activity(), ViewPager.OnPageChangeListener {
title = String.format("%s / %s", world.account.user.screenName, pagerAdapter.getName(viewPager.currentItem))
val label = getString(R.string.app_name) + " - @" + world.account.user.screenName
setTaskDescription(ActivityManager.TaskDescription(label))
+ BitmapURLTask(world.account.user.profileImageUrl, currentAccountIconImageView).execute()
}
// ------------------------ OVERRIDE METHODS ------------------------
@@ -179,26 +177,11 @@ class MainActivity : Activity(), ViewPager.OnPageChangeListener {
world.refreshListSubscriptions()
world.refreshUserMuteList()
world.refreshSavedSearches()
- Users.GetTask(account, account.userId).execute()
-
- val user = account.user
+ Users.GetTask(account, account.userId).onDoneUI { setTitle() }.execute()
// Set application title
setTitle()
- // update actionbar
- val update = {
- setTitle()
- val newUrl = user.profileImageUrl
- if (newUrl != null) {
- BitmapURLTask(newUrl, currentAccountIconImageView).execute()
- }
- }
- update() //first run
-
- currentUserBundle.detachAll()
- currentUserBundle.attach(user) { changes -> if (changes.contains(RBinding.BASIC)) update() }
-
// refresh all pages
for (i in 0..pagerAdapter.count - 1) {
val pf = pagerAdapter.getCachedFragment(i)
@@ -215,7 +198,6 @@ class MainActivity : Activity(), ViewPager.OnPageChangeListener {
}
override fun onDestroy() {
- currentUserBundle.detachAll()
Crouton.cancelAllCroutons()
// Workaround for LeakCanary
fixCroutonLeak()
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt
index 21b518d7..50cbe0aa 100644
--- a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt
@@ -53,8 +53,8 @@ import org.jetbrains.anko.startActivityForResult
import java.util.ArrayList
-class ManageAccountsActivity : Activity(), AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
- private lateinit var adapter: EditAccountsAdapter
+class ManageAccountsActivity : Activity() {
+ private val adapter by lazy { EditAccountsAdapter() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -75,11 +75,26 @@ class ManageAccountsActivity : Activity(), AdapterView.OnItemClickListener, Adap
}
setContentView(R.layout.layout_edit_list)
- adapter = EditAccountsAdapter()
listview_edit_list.adapter = adapter
- listview_edit_list.onItemClickListener = this
- listview_edit_list.onItemLongClickListener = this
+ listview_edit_list.setOnItemClickListener { adapterView: AdapterView<*>, view1: View, i: Int, l: Long ->
+ val account = adapter.getItem(i)
+ goToWorld(Application.getWorld(account.userId))
+ }
+ listview_edit_list.setOnItemLongClickListener { adapterView: AdapterView<*>, view1: View, i: Int, l: Long ->
+ if (adapter.count > 1) {
+ // remove account from application
+ val account = adapter.getItem(i)
+ ConfirmDialogFragment.show(this, getString(R.string.dialog_confirm_clear_account, account.user.screenName), {
+ adapter.removeAt(i)
+ Account.unregister(account.userId)
+ }, false)
+ true
+ } else {
+ Application.toast(R.string.notice_cant_remove_last_account)
+ false
+ }
+ }
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
@@ -115,26 +130,6 @@ class ManageAccountsActivity : Activity(), AdapterView.OnItemClickListener, Adap
return true
}
- override fun onItemClick(adapterView: AdapterView<*>, view: View, i: Int, l: Long) {
- val account = adapter.getItem(i)
- goToWorld(Application.getWorld(account.userId))
- }
-
- override fun onItemLongClick(adapterView: AdapterView<*>, view: View, i: Int, l: Long): Boolean {
- if (adapter.count > 1) {
- // remove account from application
- val account = adapter.getItem(i)
- ConfirmDialogFragment.show(this, getString(R.string.dialog_confirm_clear_account, account.user.screenName), {
- adapter.removeAt(i)
- Account.unregister(account.userId)
- }, false)
- return true
- } else {
- Application.toast(R.string.notice_cant_remove_last_account)
- return false
- }
- }
-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_edit_list_add -> startActivityForResult<OAuthActivity>(REQUEST_OAUTH)
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt b/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt
index 346d4880..403ac40b 100644
--- a/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt
@@ -39,7 +39,7 @@ import org.jetbrains.anko.coroutines.experimental.bg
import twitter4j.TwitterFactory
import twitter4j.auth.RequestToken
-class OAuthActivity : Activity(), View.OnClickListener, TextWatcher {
+class OAuthActivity : Activity(), TextWatcher {
private var token: String? = null
private var tokenSecret: String? = null
@@ -48,7 +48,29 @@ class OAuthActivity : Activity(), View.OnClickListener, TextWatcher {
setContentView(R.layout.layout_oauth)
editText_oauth_pin.addTextChangedListener(this)
- button_oauth_auth.setOnClickListener(this)
+ button_oauth_auth.setOnClickListener {
+ async(UI) {
+ val pin = editText_oauth_pin.text.toString()
+ val acct = bg {
+ val requestToken = RequestToken(token, tokenSecret)
+ TwitterFactory().instance.getOAuthAccessToken(requestToken, pin)
+ }
+
+ try {
+ val accessToken = acct.await()
+ val intent = Intent()
+ intent.putExtra(KEY_TOKEN, accessToken.token)
+ intent.putExtra(KEY_TOKEN_SECRET, accessToken.tokenSecret)
+ intent.putExtra(KEY_USER_ID, accessToken.userId)
+ intent.putExtra(KEY_SCREEN_NAME, accessToken.screenName)
+ setResult(Activity.RESULT_OK, intent)
+ } catch (e: Exception) {
+ Application.toast(R.string.notice_error_authenticate)
+ setResult(Activity.RESULT_CANCELED)
+ }
+ finish()
+ }
+ }
button_oauth_auth.isEnabled = false
if (savedInstanceState != null) {
@@ -76,32 +98,6 @@ class OAuthActivity : Activity(), View.OnClickListener, TextWatcher {
outState.putString(KEY_REQUEST_TOKEN_SECRET, tokenSecret)
}
- override fun onClick(v: View) {
- when (v.id) {
- R.id.button_oauth_auth -> async(UI) {
- val pin = editText_oauth_pin.text.toString()
- val acct = bg {
- val requestToken = RequestToken(token, tokenSecret)
- TwitterFactory().instance.getOAuthAccessToken(requestToken, pin)
- }
-
- try {
- val accessToken = acct.await()
- val intent = Intent()
- intent.putExtra(KEY_TOKEN, accessToken.token)
- intent.putExtra(KEY_TOKEN_SECRET, accessToken.tokenSecret)
- intent.putExtra(KEY_USER_ID, accessToken.userId)
- intent.putExtra(KEY_SCREEN_NAME, accessToken.screenName)
- setResult(Activity.RESULT_OK, intent)
- } catch (e: Exception) {
- Application.toast(R.string.notice_error_authenticate)
- setResult(Activity.RESULT_CANCELED)
- }
- finish()
- }
- }
- }
-
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
diff --git a/app/src/main/java/net/lacolaco/smileessence/data/Account.kt b/app/src/main/java/net/lacolaco/smileessence/data/Account.kt
index c95fcc74..e217edbb 100644
--- a/app/src/main/java/net/lacolaco/smileessence/data/Account.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/data/Account.kt
@@ -50,16 +50,7 @@ class Account {
@Column(defaultExpr = "0")
var themeIndex: Int = 0
- val user: User by lazy {
- val _user = User.fetch(userId) ?: User._makeSkeleton(userId, screenName!!)
- _user.addObserver(this) { objs ->
- if (screenName!! != _user.screenName) {
- screenName = _user.screenName
- relation().upserter().execute(this)
- }
- }
- _user
- }
+ val user: User by lazy { User.fetch(userId) ?: User._makeSkeleton(userId, screenName!!) }
val twitter: Twitter
get() {
diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/EntitySupport.kt b/app/src/main/java/net/lacolaco/smileessence/entity/EntitySupport.kt
index 3b42587a..dc548f12 100644
--- a/app/src/main/java/net/lacolaco/smileessence/entity/EntitySupport.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/entity/EntitySupport.kt
@@ -1,11 +1,10 @@
package net.lacolaco.smileessence.entity
-import net.lacolaco.smileessence.util.UIObservable
import twitter4j.*
import java.util.*
-abstract class EntitySupport(status: twitter4j.EntitySupport) : UIObservable() {
+abstract class EntitySupport(status: twitter4j.EntitySupport) {
open val mentions: List<String> = extractMentions(status.userMentionEntities)
open val hashtags: List<String> = extractHashtags(status.hashtagEntities)
open val mediaUrls: List<String> = extractMediaUrls(status.mediaEntities)
diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.kt b/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.kt
deleted file mode 100644
index 1a25cdd5..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package net.lacolaco.smileessence.entity
-
-enum class RBinding {
- // Tweet
- REACTION_COUNT,
- FAVORITERS,
- RETWEETERS,
-
- // User
- BASIC,
- DETAIL
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.kt b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.kt
index 6dbd6398..4b5c005c 100644
--- a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.kt
@@ -47,11 +47,8 @@ class Tweet private constructor(st: twitter4j.Status, myUserId: Long) : EntitySu
retweetedTweet.retweets.put(myUserId, status.currentUserRetweetId)
}
} else {
- if (favoriteCount != status.favoriteCount || retweetCount != status.retweetCount) {
favoriteCount = status.favoriteCount
retweetCount = status.retweetCount
- notifyChange(RBinding.REACTION_COUNT)
- }
if (status.isFavorited)
favoriters.add(myUserId)
@@ -71,13 +68,11 @@ class Tweet private constructor(st: twitter4j.Status, myUserId: Long) : EntitySu
fun addFavoriter(id: Long): Boolean {
val changed = originalTweet.favoriters.add(id)
- if (changed) notifyChange(RBinding.FAVORITERS)
return changed
}
fun removeFavoriter(id: Long): Boolean {
val changed = originalTweet.favoriters.remove(id)
- if (changed) notifyChange(RBinding.FAVORITERS)
return changed
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/User.kt b/app/src/main/java/net/lacolaco/smileessence/entity/User.kt
index 71afe69b..6bd3254f 100644
--- a/app/src/main/java/net/lacolaco/smileessence/entity/User.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/entity/User.kt
@@ -1,27 +1,20 @@
package net.lacolaco.smileessence.entity
-import net.lacolaco.smileessence.util.UIObservable
-
import java.util.HashMap
-class User private constructor(override val id: Long, screenName: String) : UIObservable(), IdObject {
+class User private constructor(override val id: Long, screenName: String) : IdObject {
var screenName = screenName
private set
- var name: String? = null
- private set
- var profileImageUrl: String? = null
- get() {
- val original = field
- if (original != null) {
- var url = original.substring(0, original.lastIndexOf("_"))
- val extIndex = original.lastIndexOf(".")
- if (extIndex > original.lastIndexOf("/")) {
- url += original.substring(extIndex)
- }
- return url
+ var profileImageUrl: String = "<not set>"
+ private set(value) {
+ var url = value.substring(0, value.lastIndexOf("_"))
+ val extIndex = value.lastIndexOf(".")
+ if (extIndex > value.lastIndexOf("/")) {
+ url += value.substring(extIndex)
}
- return null
+ field = url
}
+ var name: String? = null
private set
var profileBannerUrl: String? = null
private set
@@ -45,49 +38,32 @@ class User private constructor(override val id: Long, screenName: String) : UIOb
private set
private fun update(user: twitter4j.User) {
- if (isProtected != user.isProtected ||
- screenName != user.screenName ||
- name == null || name != user.name ||
- this.profileImageUrl == null || this.profileImageUrl != user.profileImageURLHttps) {
- isProtected = user.isProtected
- if (user.screenName != null)
- screenName = user.screenName
- if (user.name != null)
- name = user.name
- if (user.profileImageURLHttps != null)
- this.profileImageUrl = user.profileImageURLHttps
+ // FIXME
+ isProtected = user.isProtected
+ if (user.screenName != null)
+ screenName = user.screenName
+ if (user.name != null)
+ name = user.name
+ if (user.profileImageURLHttps != null)
+ this.profileImageUrl = user.profileImageURLHttps
- notifyChange(RBinding.BASIC)
- }
-
- if (profileBannerUrl == null || profileBannerUrl != user.profileBannerURL ||
- description == null || description != user.description ||
- location == null || location != user.location ||
- url == null || url != user.url ||
- favoritesCount != user.favouritesCount ||
- statusesCount != user.statusesCount ||
- friendsCount != user.friendsCount ||
- followersCount != user.followersCount) {
- isVerified = user.isVerified
- if (user.profileBannerURL != null)
- profileBannerUrl = user.profileBannerURL
- if (user.description != null)
- description = user.description
- if (user.location != null)
- location = user.location
- if (user.url != null)
- url = user.url
- if (user.favouritesCount != -1)
- favoritesCount = user.favouritesCount
- if (user.statusesCount != -1)
- statusesCount = user.statusesCount
- if (user.friendsCount != -1)
- friendsCount = user.friendsCount
- if (user.followersCount != -1)
- followersCount = user.followersCount
-
- notifyChange(RBinding.DETAIL)
- }
+ isVerified = user.isVerified
+ if (user.profileBannerURL != null)
+ profileBannerUrl = user.profileBannerURL
+ if (user.description != null)
+ description = user.description
+ if (user.location != null)
+ location = user.location
+ if (user.url != null)
+ url = user.url
+ if (user.favouritesCount != -1)
+ favoritesCount = user.favouritesCount
+ if (user.statusesCount != -1)
+ statusesCount = user.statusesCount
+ if (user.friendsCount != -1)
+ friendsCount = user.friendsCount
+ if (user.followersCount != -1)
+ followersCount = user.followersCount
}
// helper methods
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.kt b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.kt
index 9ea1792b..6a83d1ff 100644
--- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.kt
@@ -9,41 +9,25 @@ import twitter4j.TwitterException
class Searches {
class CreateSavedSearchTask(private val account: Account, private val query: String) : BackgroundTask<SavedSearch, Void>() {
-
- @Throws(Exception::class)
override fun doInBackground(): SavedSearch {
return SavedSearch.fromTwitter(account.twitter.savedSearches().createSavedSearch(query))
}
}
class DestroySavedSearchTask(private val account: Account, private val id: Long) : BackgroundTask<Unit, Void>() {
-
- @Throws(Exception::class)
override fun doInBackground() {
account.twitter.savedSearches().destroySavedSearch(id)
}
}
class GetAllSavedSearchesTask(private val account: Account) : BackgroundTask<List<SavedSearch>, Void>() {
-
- @Throws(Exception::class)
override fun doInBackground(): List<SavedSearch> {
- return account.twitter.savedSearches().savedSearches.map { SavedSearch.fromTwitter(it)}
+ return account.twitter.savedSearches().savedSearches.map { SavedSearch.fromTwitter(it) }
}
}
// TODO: List<Tweet> is not good here
- class SearchTask
- // --------------------------- CONSTRUCTORS ---------------------------
-
- (
- // ------------------------------ FIELDS ------------------------------
-
- private val account: Account, private val query: Query) : BackgroundTask<List<Tweet>, Void>() {
-
- // ------------------------ OVERRIDE METHODS ------------------------
-
- @Throws(TwitterException::class)
+ class SearchTask(private val account: Account, private val query: Query) : BackgroundTask<List<Tweet>, Void>() {
override fun doInBackground(): List<Tweet> {
return Tweet.fromTwitter(account.twitter.search(query).tweets, account.userId)
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.kt b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.kt
index 1af42d20..41405fb3 100644
--- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.kt
@@ -18,8 +18,6 @@ import java.util.ArrayList
class Tweets {
class GetTask(private val account: Account, private val id: Long) : BackgroundTask<Tweet, Void>() {
-
- @Throws(TwitterException::class)
override fun doInBackground(): Tweet {
return Tweet.fromTwitter(account.twitter.tweets().showStatus(id), account.userId)
}
@@ -28,8 +26,7 @@ class Tweets {
class CreateTask(private val account: Account, private val update: StatusUpdate, private val mediaPath: String, private val resizeFlag: Boolean) : BackgroundTask<Tweet, Void>() {
private var tempFilePath: String? = null
- private //decoder is not return bitmap but set option
- val mediaFile: File
+ private val mediaFile: File
get() {
val file = File(mediaPath)
if (file.length() >= MEDIA_SIZE_LIMIT && resizeFlag) {
@@ -65,7 +62,6 @@ class Tweets {
return file
}
- @Throws(TwitterException::class)
override fun doInBackground(): Tweet {
try {
if (!TextUtils.isEmpty(mediaPath)) {
@@ -88,8 +84,6 @@ class Tweets {
}
class DestroyTask(private val account: Account, private val statusID: Long) : BackgroundTask<Tweet, Void>() {
-
- @Throws(TwitterException::class)
override fun doInBackground(): Tweet {
// FIXME: Tweet.remove(t.getId());
return Tweet.fromTwitter(account.twitter.tweets().destroyStatus(statusID), account.userId)
@@ -97,7 +91,6 @@ class Tweets {
}
class GetTalkTask(private val account: Account, private val statusId: Long) : BackgroundTask<List<Tweet>, Tweet>() {
-
override fun doInBackground(): List<Tweet> {
val list = ArrayList<Tweet>()
var id = statusId
diff --git a/app/src/main/java/net/lacolaco/smileessence/util/BackgroundTask.kt b/app/src/main/java/net/lacolaco/smileessence/util/BackgroundTask.kt
index d5d16cc4..8b180941 100644
--- a/app/src/main/java/net/lacolaco/smileessence/util/BackgroundTask.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/util/BackgroundTask.kt
@@ -61,7 +61,6 @@ abstract class BackgroundTask<Result, Progress> {
}
val immediately: Result
- @Throws(Exception::class)
get() {
val result = task.get()
return if (exception == null) {
@@ -87,10 +86,9 @@ abstract class BackgroundTask<Result, Progress> {
}
}
- @Throws(Exception::class)
protected abstract fun doInBackground(): Result
- private inner class InnerAsyncTask : AsyncTask<Void, Progress, Result>() {
+ private inner class InnerAsyncTask : AsyncTask<Void, Progress?, Result>() {
override fun onPostExecute(result: Result?) {
if (!isCancelled && exception == null && cbThen != null) {
cbThen!!(result!!)
@@ -98,6 +96,7 @@ abstract class BackgroundTask<Result, Progress> {
if (cbFinish != null) {
cbFinish!!()
}
+ super.onPostExecute(result)
}
override fun doInBackground(vararg params: Void): Result? {
diff --git a/app/src/main/java/net/lacolaco/smileessence/util/BitmapURLTask.kt b/app/src/main/java/net/lacolaco/smileessence/util/BitmapURLTask.kt
index 49ffc5fb..910d5d60 100644
--- a/app/src/main/java/net/lacolaco/smileessence/util/BitmapURLTask.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/util/BitmapURLTask.kt
@@ -34,8 +34,9 @@ import java.io.InputStream
import java.net.URL
class BitmapURLTask(private val url: String, private val imageView: ImageView) : AsyncTask<Void, Void, Bitmap>() {
- override fun onPostExecute(bitmap: Bitmap) {
- imageView.setImageBitmap(bitmap)
+ override fun onPostExecute(bitmap: Bitmap?) {
+ if (bitmap != null)
+ imageView.setImageBitmap(bitmap)
}
override fun doInBackground(vararg params: Void): Bitmap? {
diff --git a/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.kt b/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.kt
deleted file mode 100644
index a8f89585..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package net.lacolaco.smileessence.util
-
-import net.lacolaco.smileessence.entity.RBinding
-
-import java.util.*
-
-abstract class UIObservable {
- private val observers = WeakHashMap<Any, (EnumSet<RBinding>) -> Unit>()
-
- fun addObserver(weakKey: Any, observer: (EnumSet<RBinding>) -> Unit) {
- synchronized(this) {
- observers.put(weakKey, observer)
- }
- }
-
- fun removeObserver(weakKey: Any) {
- synchronized(this) {
- observers.remove(weakKey)
- }
- }
-
- protected fun notifyChange(flag: RBinding) {
- notifyChange(EnumSet.of(flag))
- }
-
- protected fun notifyChange(flags: EnumSet<RBinding>) {
- val obs = ArrayList<(EnumSet<RBinding>) -> Unit>()
- synchronized(this) {
- obs.addAll(observers.values)
- }
-
- UIHandler().post {
- for (observer in obs) {
- observer(flags)
- }
- }
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/util/UIObserverBundle.kt b/app/src/main/java/net/lacolaco/smileessence/util/UIObserverBundle.kt
deleted file mode 100644
index e4386852..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/util/UIObserverBundle.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package net.lacolaco.smileessence.util
-
-import net.lacolaco.smileessence.entity.RBinding
-import java.util.*
-
-// UIObserver と UIObservable のセットを管理するオブジェクトだよ〜〜
-class UIObserverBundle {
- private val map = HashMap<UIObservable, (EnumSet<RBinding>) -> Unit>()
-
- fun detachAll(): UIObserverBundle {
- for ((key) in map) {
- key.removeObserver(this)
- }
- map.clear()
- return this
- }
-
- fun attach(observable: UIObservable, observer: (EnumSet<RBinding>) -> Unit): (EnumSet<RBinding>) -> Unit {
- observable.addObserver(this, observer)
- map.put(observable, observer)
- return observer
- }
-
- protected fun finalize() {
- detachAll()
- }
-}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt b/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt
index 58bf44b1..679b38cd 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt
@@ -7,35 +7,21 @@ import android.view.ViewGroup
import kotlinx.android.synthetic.main.list_item_status.view.*
import net.lacolaco.smileessence.R
import net.lacolaco.smileessence.World
-import net.lacolaco.smileessence.activity.MainActivity
import net.lacolaco.smileessence.data.ImageCache
import net.lacolaco.smileessence.entity.DirectMessage
-import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.entity.Tweet
import net.lacolaco.smileessence.entity.User
import net.lacolaco.smileessence.preference.UserPreferenceHelper
import net.lacolaco.smileessence.util.StringUtils
-import net.lacolaco.smileessence.util.UIObserverBundle
-import net.lacolaco.smileessence.view.adapter.CustomListAdapter
import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter
import net.lacolaco.smileessence.view.dialog.MessageDetailDialogFragment
import net.lacolaco.smileessence.view.dialog.StatusDetailDialogFragment
import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment
import net.lacolaco.smileessence.view.listener.ListItemClickListener
-import java.lang.ref.WeakReference
-import java.util.ArrayList
-
object Partials {
fun getTweetView(tweet: Tweet, world: World, activity: Activity, convertView: View?, expandEmbeddedTweets: Boolean = true): View {
val view: View = convertView ?: activity.layoutInflater.inflate(R.layout.list_item_status, null)
- var bundle: UIObserverBundle? = view.tag as UIObserverBundle?
- if (bundle != null) {
- bundle.detachAll()
- } else {
- bundle = UIObserverBundle()
- view.tag = bundle
- }
view.setOnClickListener(ListItemClickListener(activity) { DialogHelper.showDialog(activity, StatusDetailDialogFragment.newInstance(tweet)) })
@@ -46,20 +32,6 @@ object Partials {
updateViewFavorited(tweet, world, view)
updateViewEmbeddeds(tweet, world, activity, view, expandEmbeddedTweets)
- val weakView = WeakReference(view)
- val weakActivity = WeakReference(activity)
- bundle.attach(tweet.originalTweet) { changes ->
- val strongView = weakView.get()
- if (strongView != null && changes.contains(RBinding.FAVORITERS))
- updateViewFavorited(tweet, world, strongView)
- }
- bundle.attach(tweet.originalTweet.user) { changes ->
- val strongView = weakView.get()
- val strongActivity = weakActivity.get()
- if (strongView != null && strongActivity != null && changes.contains(RBinding.BASIC))
- updateViewUser(tweet.originalTweet.user, strongActivity, strongView)
- }
-
return view
}
@@ -134,13 +106,6 @@ object Partials {
fun getDirectMessageView(directMessage: DirectMessage, world: World, activity: Activity, convertView: View?): View {
val view = convertView ?: activity.layoutInflater.inflate(R.layout.list_item_status, null)
- var bundle: UIObserverBundle? = view.tag as UIObserverBundle?
- if (bundle != null) {
- bundle.detachAll()
- } else {
- bundle = UIObserverBundle()
- view.tag = bundle
- }
view.setOnClickListener(ListItemClickListener(activity) { DialogHelper.showDialog(activity, MessageDetailDialogFragment.newInstance(directMessage)) })
@@ -151,15 +116,6 @@ object Partials {
updateViewUser(directMessage.sender, activity, view)
updateViewBody(directMessage, world, view)
- val weakView = WeakReference(view)
- val weakActivity = WeakReference(activity as MainActivity)
- bundle.attach(directMessage.sender) { changes ->
- val strongView = weakView.get()
- val strongActivity = weakActivity.get()
- if (strongView != null && strongActivity != null && changes.contains(RBinding.BASIC))
- updateViewUser(directMessage.sender, strongActivity, strongView)
- }
-
return view
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
index f3c507ac..c50802d9 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
@@ -32,16 +32,12 @@ import net.lacolaco.smileessence.R
import net.lacolaco.smileessence.World
import net.lacolaco.smileessence.data.ImageCache
import net.lacolaco.smileessence.entity.Event
-import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.preference.UserPreferenceHelper
import net.lacolaco.smileessence.util.StringUtils
-import net.lacolaco.smileessence.util.UIObserverBundle
import net.lacolaco.smileessence.view.DialogHelper
import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment
import net.lacolaco.smileessence.view.listener.ListItemClickListener
-import java.lang.ref.WeakReference
-
class EventListAdapter(private val world: World, private val activity: Activity) : CustomListAdapter<Event>() {
override val list: List<Event>
get() = world.events
@@ -49,42 +45,21 @@ class EventListAdapter(private val world: World, private val activity: Activity)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = convertView ?: activity.layoutInflater.inflate(R.layout.list_item_status, parent, false)
val event = getItem(position)
- var bundle: UIObserverBundle? = view!!.tag as UIObserverBundle?
- if (bundle != null) {
- bundle.detachAll()
- } else {
- bundle = UIObserverBundle()
- view.tag = bundle
- }
val textSize = UserPreferenceHelper.instance.textSize
+ view.imageview_status_icon.setImageUrl(event.source.profileImageUrl, ImageCache.getImageLoader())
+ view.textview_status_header.text = event.formattedString
view.textview_status_header.textSize = textSize.toFloat()
-
- updateViewUser(event, view)
-
view.textview_status_text.textSize = textSize.toFloat()
view.textview_status_text.text = event.targetObject?.text ?: ""
view.textview_status_footer.textSize = (textSize - 2).toFloat()
view.textview_status_footer.text = StringUtils.dateToString(event.createdAt)
view.imageview_status_favorited.visibility = View.GONE
- view.setOnClickListener(ListItemClickListener(activity) {
+ view.setOnClickListener {
DialogHelper.showDialog(activity, UserDetailDialogFragment.newInstance(event.source))
- })
-
- val weakView = WeakReference(view)
- bundle.attach(event.source) { changes ->
- val strongView = weakView.get()
- if (strongView != null && changes.contains(RBinding.BASIC))
- updateViewUser(event, strongView)
}
return view
}
-
- private fun updateViewUser(event: Event, view: View) {
- val iconUrl = event.source.profileImageUrl
- view.imageview_status_icon.setImageUrl(iconUrl, ImageCache.getImageLoader())
- view.textview_status_header.text = event.formattedString
- }
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.kt b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.kt
index 99d6c856..ef123e55 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.kt
@@ -3,6 +3,8 @@ package net.lacolaco.smileessence.view.adapter
import java.util.*
abstract class UnorderedCustomListAdapter<T> constructor(override val list: ArrayList<T> = ArrayList<T>()) : CustomListAdapter<T>() {
+ init { update() }
+
@Synchronized
fun add(item: T) = list.add(item)
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.kt
index f1afb47e..8315ca9f 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.kt
@@ -50,26 +50,9 @@ import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter
import java.util.ArrayList
-class MessageDetailDialogFragment : StackableDialogFragment(), View.OnClickListener {
+class MessageDetailDialogFragment : StackableDialogFragment() {
private lateinit var message: DirectMessage
- override fun onClick(v: View) {
- when (v.id) {
- R.id.button_status_detail_reply -> {
- openSendMessageDialog()
- }
- R.id.button_status_detail_delete -> {
- deleteMessage()
- }
- R.id.button_status_detail_menu -> {
- openMenu()
- }
- else -> {
- dismiss()
- }
- }
- }
-
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val found = DirectMessage.fetch(arguments.getLong(KEY_MESSAGE_ID))
if (found == null) {
@@ -85,11 +68,34 @@ class MessageDetailDialogFragment : StackableDialogFragment(), View.OnClickListe
view.setBackgroundColor((messageHeader.background as ColorDrawable).color)
//--- buttons
- view.button_status_detail_reply.setOnClickListener(this)
- view.button_status_detail_delete.setOnClickListener(this)
- view.button_status_detail_delete.visibility = View.VISIBLE
+ view.button_status_detail_reply.setOnClickListener {
+ DialogHelper.showDialog(activity, SendMessageDialogFragment.newInstance(message.sender))
+ }
+ view.button_status_detail_delete.setOnClickListener {
+ ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
+ Messages.DestroyTask(world.account, message.id)
+ .onDone { x -> world.notify(R.string.notice_message_delete_succeeded) }
+ .onFail { x -> world.notifyError(R.string.notice_message_delete_failed) }
+ .execute()
+ dismiss()
+ }
+ }
// -- menu dialog
- view.button_status_detail_menu.setOnClickListener(this)
+ view.button_status_detail_menu.setOnClickListener {
+ val builder = AlertDialog.Builder(activity)
+ builder.setTitle("@" + message.sender.screenName + ": " + message.text)
+ .setItems(R.array.message_commands) { dialog, which ->
+ when (which) {
+ 0 -> {
+ SystemServiceHelper.copyToClipboard(activity, "message text", message.text)
+ world.notify(R.string.notice_copy_clipboard)
+ }
+ else -> throw IllegalStateException()
+ }
+ }
+ val dialog = builder.create()
+ dialog.show()
+ }
// -- menu embedded in dialog
val activity = activity as MainActivity
@@ -160,38 +166,6 @@ class MessageDetailDialogFragment : StackableDialogFragment(), View.OnClickListe
return AlertDialog.Builder(activity).setView(view).create()
}
- // -------------------------- OTHER METHODS --------------------------
-
- private fun deleteMessage() {
- ConfirmDialogFragment.show(activity, getString(R.string.dialog_confirm_commands)) {
- Messages.DestroyTask(world.account, message.id)
- .onDone { x -> world.notify(R.string.notice_message_delete_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_message_delete_failed) }
- .execute()
- dismiss()
- }
- }
-
- private fun openSendMessageDialog() {
- DialogHelper.showDialog(activity, SendMessageDialogFragment.newInstance(message.sender))
- }
-
- private fun openMenu() {
- val builder = AlertDialog.Builder(activity)
- builder.setTitle("@" + message.sender.screenName + ": " + message.text)
- .setItems(R.array.message_commands) { dialog, which ->
- when (which) {
- 0 -> {
- SystemServiceHelper.copyToClipboard(activity, "message text", message.text)
- world.notify(R.string.notice_copy_clipboard)
- }
- else -> throw IllegalStateException()
- }
- }
- val dialog = builder.create()
- dialog.show()
- }
-
companion object {
private val KEY_MESSAGE_ID = "message_id"
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
index 631240e9..acbcbd81 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.kt
@@ -38,135 +38,32 @@ import net.lacolaco.smileessence.command.Command
import net.lacolaco.smileessence.command.CommandAddHashtag
import net.lacolaco.smileessence.command.CommandOpenURL
import net.lacolaco.smileessence.command.CommandOpenUserDetail
-import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.entity.Tweet
import net.lacolaco.smileessence.preference.UserPreferenceHelper
import net.lacolaco.smileessence.twitter.task.TweetReactions
import net.lacolaco.smileessence.twitter.task.Tweets
import net.lacolaco.smileessence.util.SystemServiceHelper
-import net.lacolaco.smileessence.util.UIObserverBundle
import net.lacolaco.smileessence.view.DialogHelper
import net.lacolaco.smileessence.view.Partials
-import net.lacolaco.smileessence.view.adapter.CustomListAdapter
import net.lacolaco.smileessence.view.adapter.TimelineAdapter
import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter
import org.jetbrains.anko.browse
-import java.lang.ref.WeakReference
import java.util.ArrayList
import java.util.LinkedHashSet
-class StatusDetailDialogFragment : StackableDialogFragment(), View.OnClickListener {
+class StatusDetailDialogFragment : StackableDialogFragment() {
private lateinit var tweet: Tweet
- override fun onClick(v: View) {
- when (v.id) {
- R.id.button_status_detail_reply -> {
- val originalTweet = tweet.originalTweet
-
- val builder = StringBuilder()
- builder.append("@" + originalTweet.user.screenName + " ")
-
- for (screenName in originalTweet.mentions) {
- if (screenName != world.account.user.screenName)
- builder.append("@$screenName ")
- }
- val text = builder.toString()
- val selStart = originalTweet.user.screenName.length + 2 // "@" and " "
-
- world.postState.beginTransaction()
- .clear()
- .insertText(0, text)
- .setInReplyTo(originalTweet)
- .setSelection(selStart, text.length)
- .commitWithOpen(activity as MainActivity)
- }
- R.id.button_status_detail_retweet -> {
- val account = world.account
- confirm({
- if (tweet.isRetweetedBy(account.userId)) {
- Tweets.DestroyTask(account, tweet.getRetweetIdBy(account.userId))
- .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
- .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
- .execute()
- dismiss()
- } else {
- TweetReactions.RetweetTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_retweet_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_retweet_failed) }
- .execute()
- }
- })
- }
- R.id.button_status_detail_favorite -> {
- val account = world.account
- if (tweet.isFavoritedBy(account.userId)) {
- TweetReactions.UnfavoriteTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_unfavorite_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_unfavorite_failed) }
- .execute()
- } else {
- TweetReactions.FavoriteTask(account, tweet.id)
- .onDone { x -> world.notify(R.string.notice_favorite_succeeded) }
- .onFail { x -> world.notifyError(R.string.notice_favorite_failed) }
- .execute()
- }
- }
- R.id.button_status_detail_delete -> {
- confirm({
- Tweets.DestroyTask(world.account, tweet.originalTweet.id)
- .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
- .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
- .execute()
- dismiss()
- })
- }
- R.id.button_status_detail_menu -> {
- val builder = AlertDialog.Builder(activity)
- builder.setTitle("@" + tweet.user.screenName + ": " + tweet.text)
- .setItems(R.array.status_commands) { dialog, which ->
- when (which) {
- 0 -> {
- val text = String.format("@%s ", tweet.originalTweet.user.screenName)
- world.postState.beginTransaction().insertText(0, text).moveCursor(text.length).commit()
- world.notify(R.string.notice_add_to_reply)
- }
- 1 -> {
- DialogHelper.showDialog(activity, TalkChainDialogFragment.newInstance(tweet))
- }
- 2 -> browse(tweet.originalTweet.twitterUrl)
- 3 -> {
- SystemServiceHelper.copyToClipboard(activity, "tweet text", tweet.originalTweet.text)
- world.notify(R.string.notice_copy_clipboard)
- }
- 4 -> {
- val statusURL = tweet.originalTweet.twitterUrl
- SystemServiceHelper.copyToClipboard(activity, "tweet url", statusURL)
- world.notify(R.string.notice_copy_clipboard)
- }
- else -> throw IllegalStateException()
- }
- }
- val dialog = builder.create()
- dialog.show()
- }
- else -> {
- dismiss()
- }
- }
- }
-
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val found = Tweet.fetch(arguments.getLong(KEY_STATUS_ID))
- if (found == null) { // trying to open deleted tweet?
+ if (found == null) {
world.notifyError(R.string.notice_error_show_status)
return DisposeDialog(activity)
}
tweet = found
val view = activity.layoutInflater.inflate(R.layout.dialog_status_detail, null)
- val bundle = UIObserverBundle()
- view.tag = bundle
val statusHeader = Partials.getTweetView(tweet, world, activity, view.layout_status_header)
statusHeader.isClickable = false
@@ -176,17 +73,6 @@ class StatusDetailDialogFragment : StackableDialogFragment(), View.OnClickListen
updateViewButtons(view)
setupViewMenu(view)
- val weakView = WeakReference(view)
- bundle.attach(tweet.originalTweet) { changes ->
- val strongView = weakView.get()
- if (strongView != null && activity != null) {
- if (changes.contains(RBinding.REACTION_COUNT))
- updateViewReactions(strongView)
- if (changes.contains(RBinding.FAVORITERS) || changes.contains(RBinding.RETWEETERS))
- updateViewButtons(strongView)
- }
- }
-
val adapter = TimelineAdapter(activity, world)
view.listview_status_detail_reply_to.adapter = adapter
@@ -216,6 +102,7 @@ class StatusDetailDialogFragment : StackableDialogFragment(), View.OnClickListen
view.image_status_detail_fav_count.visibility = View.GONE
view.textview_status_detail_fav_count.visibility = View.GONE
}
+ view.button_status_detail_favorite.setState(tweet.isFavoritedBy(world.account.userId))
if (tweet.retweetCount > 0) {
view.textview_status_detail_rt_count.text = Integer.toString(tweet.retweetCount)
@@ -225,24 +112,100 @@ class StatusDetailDialogFragment : StackableDialogFragment(), View.OnClickListen
view.image_status_detail_rt_count.visibility = View.GONE
view.textview_status_detail_rt_count.visibility = View.GONE
}
+ view.button_status_detail_retweet.setState(tweet.isRetweetedBy(world.account.userId))
}
private fun updateViewButtons(view: View) {
- val account = world.account
-
- //--- buttons
- view.button_status_detail_reply.setOnClickListener(this)
+ view.button_status_detail_reply.setOnClickListener {
+ val originalTweet = tweet.originalTweet
- view.button_status_detail_retweet.setOnClickListener(this)
- view.button_status_detail_retweet.setState(tweet.isRetweetedBy(account.userId))
+ val builder = StringBuilder()
+ builder.append("@${originalTweet.user.screenName} ")
- view.button_status_detail_favorite.setOnClickListener(this)
- view.button_status_detail_favorite.setState(tweet.isFavoritedBy(account.userId))
-
- view.button_status_detail_delete.setOnClickListener(this)
- view.button_status_detail_delete.visibility = if (tweet.originalTweet.user === account.user) View.VISIBLE else View.GONE
+ for (screenName in originalTweet.mentions) {
+ if (screenName != world.account.user.screenName)
+ builder.append("@$screenName ")
+ }
+ val text = builder.toString()
+ val selStart = originalTweet.user.screenName.length + 2 // "@" and " "
- view.button_status_detail_menu.setOnClickListener(this)
+ world.postState.beginTransaction()
+ .clear()
+ .insertText(0, text)
+ .setInReplyTo(originalTweet)
+ .setSelection(selStart, text.length)
+ .commitWithOpen(activity as MainActivity)
+ }
+ view.button_status_detail_retweet.setOnClickListener {
+ val account = world.account
+ confirm({
+ if (tweet.isRetweetedBy(account.userId)) {
+ Tweets.DestroyTask(account, tweet.getRetweetIdBy(account.userId))
+ .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
+ .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
+ .onFinishUI { updateViewReactions(view) }
+ .execute()
+ } else {
+ TweetReactions.RetweetTask(account, tweet.id)
+ .onDone { x -> world.notify(R.string.notice_retweet_succeeded) }
+ .onFail { x -> world.notifyError(R.string.notice_retweet_failed) }
+ .onFinishUI { updateViewReactions(view) }
+ .execute()
+ }
+ })
+ }
+ view.button_status_detail_favorite.setOnClickListener {
+ val account = world.account
+ if (tweet.isFavoritedBy(account.userId)) {
+ TweetReactions.UnfavoriteTask(account, tweet.id)
+ .onDone { x -> world.notify(R.string.notice_unfavorite_succeeded) }
+ .onFail { x -> world.notifyError(R.string.notice_unfavorite_failed) }
+ .onFinishUI { updateViewReactions(view) }
+ .execute()
+ } else {
+ TweetReactions.FavoriteTask(account, tweet.id)
+ .onDone { x -> world.notify(R.string.notice_favorite_succeeded) }
+ .onFail { x -> world.notifyError(R.string.notice_favorite_failed) }
+ .onFinishUI { updateViewReactions(view) }
+ .execute()
+ }
+ }
+ view.button_status_detail_delete.visibility = if (tweet.originalTweet.user === world.account.user) View.VISIBLE else View.GONE
+ view.button_status_detail_delete.setOnClickListener {
+ confirm({
+ Tweets.DestroyTask(world.account, tweet.originalTweet.id)
+ .onDone { t -> world.notify(R.string.notice_status_delete_succeeded) }
+ .onFail { e -> world.notifyError(R.string.notice_status_delete_failed) }
+ .execute()
+ dismiss()
+ })
+ }
+ view.button_status_detail_menu.setOnClickListener {
+ val builder = AlertDialog.Builder(activity)
+ builder.setTitle("@" + tweet.user.screenName + ": " + tweet.text)
+ .setItems(R.array.status_commands) { dialog, which ->
+ when (which) {
+ 0 -> {
+ val text = String.format("@%s ", tweet.originalTweet.user.screenName)
+ world.postState.beginTransaction().insertText(0, text).moveCursor(text.length).commit()
+ world.notify(R.string.notice_add_to_reply)
+ }
+ 1 -> DialogHelper.showDialog(activity, TalkChainDialogFragment.newInstance(tweet))
+ 2 -> browse(tweet.originalTweet.twitterUrl)
+ 3 -> {
+ SystemServiceHelper.copyToClipboard(activity, "tweet text", tweet.originalTweet.text)
+ world.notify(R.string.notice_copy_clipboard)
+ }
+ 4 -> {
+ SystemServiceHelper.copyToClipboard(activity, "tweet url", tweet.originalTweet.twitterUrl)
+ world.notify(R.string.notice_copy_clipboard)
+ }
+ else -> throw IllegalStateException()
+ }
+ }
+ val dialog = builder.create()
+ dialog.show()
+ }
}
private fun setupViewMenu(view: View) {
@@ -250,18 +213,14 @@ class StatusDetailDialogFragment : StackableDialogFragment(), View.OnClickListen
val commands = ArrayList<Command>()
if (tweet.retweetedTweet != null && tweet.user !== tweet.retweetedTweet!!.user)
commands.add(CommandOpenUserDetail(activity, tweet.user.screenName))
- for (screenName in ArrayList(LinkedHashSet(tweet.mentions))) {
+ for (screenName in ArrayList(LinkedHashSet(tweet.mentions)))
commands.add(CommandOpenUserDetail(activity, screenName))
- }
- for (hashtag in tweet.hashtags) {
+ for (hashtag in tweet.hashtags)
commands.add(CommandAddHashtag(activity, hashtag))
- }
- for (url in tweet.urlsExpanded) {
+ for (url in tweet.urlsExpanded)
commands.add(CommandOpenURL(activity, url))
- }
- for (url in tweet.mediaUrls) {
+ for (url in tweet.mediaUrls)
commands.add(CommandOpenURL(activity, url))
- }
if (commands.size > 0) {
view.detail_dialog_divider_bottom.visibility = View.VISIBLE
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
index b9b60cc6..e5d2bc68 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.kt
@@ -37,12 +37,10 @@ import com.handmark.pulltorefresh.library.PullToRefreshBase
import kotlinx.android.synthetic.main.dialog_user_detail.view.*
import net.lacolaco.smileessence.R
import net.lacolaco.smileessence.data.ImageCache
-import net.lacolaco.smileessence.entity.RBinding
import net.lacolaco.smileessence.entity.User
import net.lacolaco.smileessence.twitter.task.Timelines
import net.lacolaco.smileessence.twitter.task.Users
import net.lacolaco.smileessence.util.UIHandler
-import net.lacolaco.smileessence.util.UIObserverBundle
import net.lacolaco.smileessence.view.DialogHelper
import net.lacolaco.smileessence.view.ThreeStateButton
import net.lacolaco.smileessence.view.adapter.TimelineAdapter
@@ -50,7 +48,6 @@ import org.jetbrains.anko.browse
class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener, PullToRefreshBase.OnRefreshListener2<ListView> {
private val adapter by lazy { TimelineAdapter(activity, world) }
- private val observerBundle by lazy { UIObserverBundle() }
private lateinit var user: User
override fun onClick(v: View) {
@@ -171,11 +168,6 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
.execute()
}
- override fun onDestroy() {
- observerBundle.detachAll()
- super.onDestroy()
- }
-
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val found = User.fetch(arguments.getLong(KEY_USER_ID))
if (found == null) {
@@ -210,15 +202,6 @@ class UserDetailDialogFragment : StackableDialogFragment(), View.OnClickListener
executeUserTimelineTask(v, adapter)
updateRelationship(v)
- observerBundle.attach(user) { changes ->
- if (activity != null) {
- if (changes.contains(RBinding.BASIC))
- updateUserDataBasic(v)
- if (changes.contains(RBinding.DETAIL))
- updateUserDataDetail(v)
- }
- }
-
return AlertDialog.Builder(activity)
.setView(v)
.setCancelable(true)