diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-13 23:05:45 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-13 23:05:45 +0900 |
commit | 9620d8e7dcbdd7a6111a4f54818233aac02d417c (patch) | |
tree | 1ebd6451ae70fce38a49a526c71848bcf9fd47e9 /app/src/main/java/net | |
parent | f3003892c64ed6c40ed8fda5b1cf29f094e60c72 (diff) | |
download | SmileEssence-9620d8e7dcbdd7a6111a4f54818233aac02d417c.tar.gz |
get rid of anko
Diffstat (limited to 'app/src/main/java/net')
11 files changed, 40 insertions, 33 deletions
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 8edb6f30..983da6cf 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.kt @@ -33,8 +33,6 @@ import net.lacolaco.smileessence.view.confirm import net.lacolaco.smileessence.view.dialog.StatusDetailDialogFragment import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment import net.lacolaco.smileessence.view.page.* -import org.jetbrains.anko.browse -import org.jetbrains.anko.startActivity import java.io.IOException import java.io.InputStream import java.net.URL @@ -335,10 +333,13 @@ class MainActivity : Activity(), ViewPager.OnPageChangeListener { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - android.R.id.home -> - startActivity<ManageAccountsActivity>(ManageAccountsActivity.INTENT_KEY_NOINIT to true) - R.id.actionbar_setting -> startActivity<SettingActivity>() - R.id.actionbar_edit_extraction -> startActivity<EditExtractionActivity>() + android.R.id.home -> { + val intent = Intent(this, ManageAccountsActivity::class.java) + intent.putExtra(ManageAccountsActivity.INTENT_KEY_NOINIT, true) + startActivity(intent) + } + R.id.actionbar_setting -> startActivity(Intent(this, SettingActivity::class.java)) + R.id.actionbar_edit_extraction -> startActivity(Intent(this, EditExtractionActivity::class.java)) R.id.actionbar_aclog -> browse(world.account.user.aclogTimelineURL) else -> return super.onOptionsItemSelected(item) } 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 a9c8e6e1..d53e94a7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt +++ b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.kt @@ -15,17 +15,15 @@ import android.widget.AdapterView import android.widget.BaseAdapter import kotlinx.android.synthetic.main.layout_edit_list.* import kotlinx.android.synthetic.main.list_item_account.view.* -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.async import net.lacolaco.smileessence.Application import net.lacolaco.smileessence.R import net.lacolaco.smileessence.World import net.lacolaco.smileessence.data.Account import net.lacolaco.smileessence.data.ImageCache import net.lacolaco.smileessence.logging.Logger +import net.lacolaco.smileessence.util.bg +import net.lacolaco.smileessence.util.launchUi import net.lacolaco.smileessence.view.confirm -import org.jetbrains.anko.coroutines.experimental.bg -import org.jetbrains.anko.startActivityForResult import java.util.* class ManageAccountsActivity : Activity() { @@ -117,7 +115,7 @@ class ManageAccountsActivity : Activity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_edit_list_add -> startActivityForResult<OAuthActivity>(REQUEST_OAUTH) + R.id.menu_edit_list_add -> startActivityForResult(Intent(this, OAuthActivity::class.java), REQUEST_OAUTH) android.R.id.home -> safeFinish() else -> return super.onOptionsItemSelected(item) } @@ -145,7 +143,7 @@ class ManageAccountsActivity : Activity() { private fun receiveOAuth(requestCode: Int, resultCode: Int, data: Intent?) { if (resultCode == Activity.RESULT_OK) { - async(UI) { + launchUi { data!! adapter.add(bg { Account.register( 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 5e946fc9..334c84cc 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt +++ b/app/src/main/java/net/lacolaco/smileessence/activity/OAuthActivity.kt @@ -6,12 +6,11 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import kotlinx.android.synthetic.main.layout_oauth.* -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.async import net.lacolaco.smileessence.Application import net.lacolaco.smileessence.R import net.lacolaco.smileessence.logging.Logger -import org.jetbrains.anko.coroutines.experimental.bg +import net.lacolaco.smileessence.util.bg +import net.lacolaco.smileessence.util.launchUi import twitter4j.TwitterFactory import twitter4j.auth.RequestToken @@ -25,7 +24,7 @@ class OAuthActivity : Activity(), TextWatcher { editText_oauth_pin.addTextChangedListener(this) button_oauth_auth.setOnClickListener { - async(UI) { + launchUi { val pin = editText_oauth_pin.text.toString() val acct = bg { val requestToken = RequestToken(token, tokenSecret) @@ -53,7 +52,7 @@ class OAuthActivity : Activity(), TextWatcher { token = savedInstanceState.getString(KEY_REQUEST_TOKEN) tokenSecret = savedInstanceState.getString(KEY_REQUEST_TOKEN_SECRET) } else - async(UI) { + launchUi { val reqt = bg { TwitterFactory().instance.getOAuthRequestToken("oob") } try { diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt index 42bc8b7e..36136fcf 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt @@ -1,7 +1,7 @@ package net.lacolaco.smileessence.command import net.lacolaco.smileessence.activity.MainActivity -import org.jetbrains.anko.browse +import net.lacolaco.smileessence.util.browse class CommandOpenURL(activity: MainActivity, override val text: String) : Command(activity) { override fun execute(): Boolean { 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 dc2d1a6a..b5327d5a 100644 --- a/app/src/main/java/net/lacolaco/smileessence/data/Account.kt +++ b/app/src/main/java/net/lacolaco/smileessence/data/Account.kt @@ -9,9 +9,6 @@ import twitter4j.TwitterStreamFactory import twitter4j.auth.AccessToken import twitter4j.conf.ConfigurationBuilder -import kotlin.collections.ArrayList -import kotlin.collections.LinkedHashMap - class Account private constructor( val id: Long, private val oauthToken: String, diff --git a/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.kt b/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.kt index 223bedd8..7c1e1384 100644 --- a/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.kt +++ b/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.kt @@ -1,9 +1,7 @@ package net.lacolaco.smileessence.data import android.content.ContentValues - import java.util.regex.Pattern -import kotlin.collections.HashSet class ExtractionWord private constructor(val patternString: String) { val pattern: Pattern by lazy { diff --git a/app/src/main/java/net/lacolaco/smileessence/util/IntentHelper.kt b/app/src/main/java/net/lacolaco/smileessence/util/IntentHelper.kt new file mode 100644 index 00000000..5614ec65 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/util/IntentHelper.kt @@ -0,0 +1,19 @@ +package net.lacolaco.smileessence.util + +import android.app.Fragment +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.net.Uri + +fun Context.browse(url: String) { + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + startActivity(intent) + } catch (e: ActivityNotFoundException) { + e.printStackTrace() + } +} + +fun Fragment.browse(url: String) = activity.browse(url) 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 66db741e..81abb9fb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt +++ b/app/src/main/java/net/lacolaco/smileessence/view/Partials.kt @@ -139,7 +139,7 @@ object Partials { val color = array.getColor(0, 0) array.recycle() if (color == 0) { - throw RuntimeException ("[BUG] can't get styled color from attr ID: " + resId) + throw RuntimeException("[BUG] can't get styled color from attr ID: " + resId) } else { return color } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/SettingFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/SettingFragment.kt index 670ca049..019e02b5 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SettingFragment.kt +++ b/app/src/main/java/net/lacolaco/smileessence/view/SettingFragment.kt @@ -1,6 +1,7 @@ package net.lacolaco.smileessence.view import android.app.AlertDialog +import android.content.Intent import android.content.SharedPreferences import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.os.Bundle @@ -14,7 +15,6 @@ import net.lacolaco.smileessence.Application import net.lacolaco.smileessence.BuildConfig import net.lacolaco.smileessence.R import net.lacolaco.smileessence.activity.LicenseActivity -import org.jetbrains.anko.startActivity class SettingFragment : PreferenceFragment(), OnSharedPreferenceChangeListener, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { @@ -39,7 +39,7 @@ class SettingFragment : PreferenceFragment(), OnSharedPreferenceChangeListener, if (key.contentEquals(getString(R.string.key_setting_application_information))) { openAppInfoDialog() } else if (key.contentEquals(getString(R.string.key_setting_licenses))) - activity.startActivity<LicenseActivity>() + activity.startActivity(Intent(activity, LicenseActivity::class.java)) return true } 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 56270f7a..3869a3d7 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 @@ -17,17 +17,13 @@ import net.lacolaco.smileessence.entity.Tweet import net.lacolaco.smileessence.preference.UserPreferenceHelper import net.lacolaco.smileessence.twitter.TwitterTaskException import net.lacolaco.smileessence.twitter.task.* -import net.lacolaco.smileessence.util.SystemServiceHelper -import net.lacolaco.smileessence.util.bg -import net.lacolaco.smileessence.util.launchBg -import net.lacolaco.smileessence.util.launchUi +import net.lacolaco.smileessence.util.* import net.lacolaco.smileessence.view.DialogHelper import net.lacolaco.smileessence.view.Partials import net.lacolaco.smileessence.view.PopupMenu import net.lacolaco.smileessence.view.adapter.TimelineAdapter import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter import net.lacolaco.smileessence.view.confirm -import org.jetbrains.anko.browse import java.util.* class StatusDetailDialogFragment : StackableDialogFragment() { 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 d1fef95c..e68a38a1 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 @@ -13,16 +13,15 @@ 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.User -import net.lacolaco.smileessence.logging.Logger import net.lacolaco.smileessence.twitter.TwitterTaskException import net.lacolaco.smileessence.twitter.task.* +import net.lacolaco.smileessence.util.browse import net.lacolaco.smileessence.util.launchUi import net.lacolaco.smileessence.view.DialogHelper import net.lacolaco.smileessence.view.PopupMenu import net.lacolaco.smileessence.view.ThreeStateButton import net.lacolaco.smileessence.view.adapter.TimelineAdapter import net.lacolaco.smileessence.view.confirm -import org.jetbrains.anko.browse class UserDetailDialogFragment : StackableDialogFragment() { private val adapter by lazy { TimelineAdapter(activity, world) } |