2017-02-02 16:50:30 +01:00
|
|
|
package org.mariotaku.twidere.model.tab.conf
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.TextView
|
2017-02-02 17:27:21 +01:00
|
|
|
import org.mariotaku.microblog.library.twitter.model.Location
|
2017-02-02 16:50:30 +01:00
|
|
|
import org.mariotaku.twidere.R
|
|
|
|
import org.mariotaku.twidere.activity.TrendsLocationSelectorActivity
|
2017-02-05 13:42:18 +01:00
|
|
|
import org.mariotaku.twidere.annotation.AccountType
|
2017-02-02 16:50:30 +01:00
|
|
|
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY
|
2017-02-02 17:27:21 +01:00
|
|
|
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_LOCATION
|
2017-03-01 15:12:25 +01:00
|
|
|
import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment
|
2017-02-05 13:42:18 +01:00
|
|
|
import org.mariotaku.twidere.model.AccountDetails
|
2017-04-17 15:10:14 +02:00
|
|
|
import org.mariotaku.twidere.model.tab.StringHolder
|
2017-02-02 16:50:30 +01:00
|
|
|
import org.mariotaku.twidere.model.tab.TabConfiguration
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mariotaku on 2016/12/5.
|
|
|
|
*/
|
2017-02-02 17:27:21 +01:00
|
|
|
open class TrendsLocationExtraConfiguration(
|
2017-04-17 15:10:14 +02:00
|
|
|
key: String,
|
|
|
|
title: StringHolder
|
|
|
|
) : TabConfiguration.ExtraConfiguration(key, title) {
|
2017-02-02 16:50:30 +01:00
|
|
|
|
|
|
|
open var value: Place? = null
|
2017-02-02 17:27:21 +01:00
|
|
|
set(value) {
|
|
|
|
field = value
|
|
|
|
if (value != null) {
|
|
|
|
summaryView.visibility = View.VISIBLE
|
|
|
|
summaryView.text = value.name
|
|
|
|
} else {
|
|
|
|
summaryView.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
2017-02-02 16:50:30 +01:00
|
|
|
|
2017-02-02 17:27:21 +01:00
|
|
|
private lateinit var summaryView: TextView
|
2017-02-05 13:42:18 +01:00
|
|
|
|
2017-04-17 15:10:14 +02:00
|
|
|
constructor(key: String, titleRes: Int) : this(key, StringHolder.resource(titleRes))
|
|
|
|
|
2017-02-02 16:50:30 +01:00
|
|
|
override fun onCreateView(context: Context, parent: ViewGroup): View {
|
|
|
|
return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_checkbox, parent, false)
|
|
|
|
}
|
|
|
|
|
2017-03-01 15:12:25 +01:00
|
|
|
override fun onViewCreated(context: Context, view: View, fragment: TabEditorDialogFragment) {
|
2017-02-02 16:50:30 +01:00
|
|
|
super.onViewCreated(context, view, fragment)
|
2017-06-19 06:11:28 +02:00
|
|
|
val titleView = view.findViewById<TextView>(android.R.id.title)
|
2017-02-02 16:50:30 +01:00
|
|
|
titleView.text = title.createString(context)
|
2017-06-19 06:11:28 +02:00
|
|
|
|
|
|
|
summaryView = view.findViewById<TextView>(android.R.id.summary)
|
2017-02-02 17:27:21 +01:00
|
|
|
summaryView.visibility = View.GONE
|
2017-02-02 16:50:30 +01:00
|
|
|
view.setOnClickListener {
|
|
|
|
val account = fragment.account ?: return@setOnClickListener
|
|
|
|
val intent = Intent(context, TrendsLocationSelectorActivity::class.java)
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT_KEY, account.key)
|
2017-02-02 17:27:21 +01:00
|
|
|
fragment.startExtraConfigurationActivityForResult(this@TrendsLocationExtraConfiguration, intent, 1)
|
2017-02-02 16:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-01 15:12:25 +01:00
|
|
|
override fun onActivityResult(fragment: TabEditorDialogFragment, requestCode: Int, resultCode: Int, data: Intent?) {
|
2017-02-02 16:50:30 +01:00
|
|
|
when (requestCode) {
|
|
|
|
1 -> {
|
2017-02-02 17:27:21 +01:00
|
|
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
|
|
|
val location = data.getParcelableExtra<Location>(EXTRA_LOCATION)
|
|
|
|
value = Place(location.woeid, location.name)
|
2017-02-02 16:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-05 13:42:18 +01:00
|
|
|
override fun onAccountSelectionChanged(account: AccountDetails?) {
|
|
|
|
super.onAccountSelectionChanged(account)
|
2017-06-19 06:11:28 +02:00
|
|
|
val titleView: TextView = view.findViewById(android.R.id.title)
|
|
|
|
val summaryView: TextView = view.findViewById(android.R.id.summary)
|
2017-02-05 13:42:18 +01:00
|
|
|
val canSelectLocation = account?.type == AccountType.TWITTER
|
|
|
|
view.isEnabled = canSelectLocation
|
|
|
|
titleView.isEnabled = canSelectLocation
|
|
|
|
summaryView.isEnabled = canSelectLocation
|
|
|
|
if (!canSelectLocation) {
|
|
|
|
value = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 16:50:30 +01:00
|
|
|
data class Place(var woeId: Int, var name: String)
|
|
|
|
}
|