code cleanup

This commit is contained in:
Mariotaku Lee 2016-12-15 09:33:47 +08:00
parent afd141e426
commit 1e4501f333
3 changed files with 17 additions and 18 deletions

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.util
import android.accounts.Account
import android.accounts.AccountManager
import android.accounts.OnAccountsUpdateListener
import android.app.Application
@ -28,7 +29,6 @@ import io.fabric.sdk.android.Fabric
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.Constants
import java.util.*
/**
* Created by mariotaku on 15/7/8.
@ -55,7 +55,7 @@ class TwidereBugReporter : BugReporter(), Constants {
Crashlytics.setString("build.product", Build.PRODUCT)
val am = AccountManager.get(application)
am.addOnAccountsUpdatedListenerSafe(OnAccountsUpdateListener { accounts ->
Crashlytics.setString("twidere.accounts", Arrays.toString(accounts))
Crashlytics.setString("twidere.accounts", accounts.joinToString(transform = Account::name))
}, updateImmediately = true)
}

View File

@ -476,32 +476,31 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
super.onCreate(savedInstanceState)
GeneralComponentHelper.build(this).inject(this)
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
nameFirst = preferences.getBoolean(KEY_NAME_FIRST)
nameFirst = preferences[nameFirstKey]
setContentView(R.layout.activity_compose)
mediaPreviewAdapter = MediaPreviewAdapter(this, PreviewGridOnStartDragListener(this))
itemTouchHelper = ItemTouchHelper(AttachedMediaItemTouchHelperCallback(mediaPreviewAdapter))
setFinishOnTouchOutside(false)
val accounts = AccountUtils.getAllAccountDetails(AccountManager.get(this))
val am = AccountManager.get(this)
val accounts = AccountUtils.getAccounts(am)
if (accounts.isEmpty()) {
val intent = Intent(INTENT_ACTION_TWITTER_LOGIN)
intent.setClass(this, SignInActivity::class.java)
startActivity(intent)
Toast.makeText(this, R.string.no_account, Toast.LENGTH_SHORT).show()
shouldSkipDraft = true
finish()
return
}
val defaultAccountIds = accounts.map { it.key }.toTypedArray()
val accountDetails = AccountUtils.getAllAccountDetails(am, accounts)
val defaultAccountIds = accountDetails.map(AccountDetails::key).toTypedArray()
menuBar.setOnMenuItemClickListener(this)
setupEditText()
accountSelectorContainer.setOnClickListener(this)
accountSelectorButton.setOnClickListener(this)
replyLabel.setOnClickListener(this)
locationSwitch.max = LOCATION_OPTIONS.size
val attachLocation = preferences.getBoolean(KEY_ATTACH_LOCATION)
val attachPreciseLocation = preferences.getBoolean(KEY_ATTACH_PRECISE_LOCATION)
val attachLocation = preferences[attachLocationKey]
val attachPreciseLocation = preferences[attachPreciseLocationKey]
if (attachLocation) {
if (attachPreciseLocation) {
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_COORDINATE)
@ -552,7 +551,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
accountSelector.itemAnimator = DefaultItemAnimator()
accountsAdapter = AccountIconsAdapter(this).apply {
setAccounts(accounts)
setAccounts(accountDetails)
}
accountSelector.adapter = accountsAdapter

View File

@ -21,8 +21,9 @@ import org.mariotaku.ktextension.set
import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.Constants.*
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_AUTH_TOKEN_TYPE
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_TYPE
import org.mariotaku.twidere.activity.ColorPickerDialogActivity
import org.mariotaku.twidere.activity.SignInActivity
import org.mariotaku.twidere.adapter.AccountDetailsAdapter
import org.mariotaku.twidere.annotation.Referral
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY
@ -105,9 +106,8 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.add_account -> {
val intent = Intent(INTENT_ACTION_TWITTER_LOGIN)
intent.setClass(activity, SignInActivity::class.java)
startActivity(intent)
AccountManager.get(context).addAccount(ACCOUNT_TYPE, ACCOUNT_AUTH_TOKEN_TYPE,
null, null, activity, null, null)
}
}
return super.onOptionsItemSelected(item)
@ -117,8 +117,8 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
inflater.inflate(R.menu.menu_accounts_manager, menu)
}
override fun onContextItemSelected(item: MenuItem?): Boolean {
val menuInfo = item!!.menuInfo as? AdapterContextMenuInfo ?: return false
override fun onContextItemSelected(item: MenuItem): Boolean {
val menuInfo = item.menuInfo as? AdapterContextMenuInfo ?: return false
val details = adapter.getItem(menuInfo.position) ?: return false
when (item.itemId) {
R.id.set_color -> {