Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserProfileEditorFragment.kt

578 lines
24 KiB
Kotlin
Raw Normal View History

2016-07-02 05:54:53 +02:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.fragment
2016-07-08 06:46:54 +02:00
import android.app.Activity
2016-07-02 05:54:53 +02:00
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
2020-01-26 08:35:15 +01:00
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
import androidx.loader.app.LoaderManager.LoaderCallbacks
import androidx.loader.content.Loader
2016-07-06 03:18:12 +02:00
import android.text.TextUtils
2016-07-02 05:54:53 +02:00
import android.text.TextUtils.isEmpty
import android.view.*
import android.view.View.OnClickListener
import android.widget.Toast
import com.twitter.Validator
import kotlinx.android.synthetic.main.fragment_user_profile_editor.*
2017-04-22 16:14:40 +02:00
import nl.komponents.kovenant.combine.and
import nl.komponents.kovenant.ui.promiseOnUi
2016-07-02 05:54:53 +02:00
import org.mariotaku.abstask.library.AbstractTask
import org.mariotaku.abstask.library.TaskStarter
2017-03-27 05:08:09 +02:00
import org.mariotaku.ktextension.dismissDialogFragment
2016-12-04 04:58:03 +01:00
import org.mariotaku.microblog.library.MicroBlog
2016-07-02 05:54:53 +02:00
import org.mariotaku.microblog.library.MicroBlogException
2017-04-22 16:14:40 +02:00
import org.mariotaku.microblog.library.mastodon.Mastodon
import org.mariotaku.microblog.library.mastodon.model.AccountUpdate
2016-07-02 05:54:53 +02:00
import org.mariotaku.microblog.library.twitter.model.ProfileUpdate
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.ColorPickerDialogActivity
2017-01-22 17:23:08 +01:00
import org.mariotaku.twidere.activity.ThemedMediaPickerActivity
2017-04-22 16:14:40 +02:00
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.loadProfileBanner
2017-03-02 03:42:40 +01:00
import org.mariotaku.twidere.extension.loadProfileImage
2017-04-22 16:14:40 +02:00
import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable
2017-04-20 19:23:11 +02:00
import org.mariotaku.twidere.extension.model.api.toParcelable
2016-12-08 16:45:07 +01:00
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
2016-07-02 05:54:53 +02:00
import org.mariotaku.twidere.loader.ParcelableUserLoader
2016-12-04 06:45:57 +01:00
import org.mariotaku.twidere.model.AccountDetails
2016-07-02 05:54:53 +02:00
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.SingleResponse
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.util.ParcelableUserUtils
2017-04-20 14:04:37 +02:00
import org.mariotaku.twidere.task.*
2016-07-02 05:54:53 +02:00
import org.mariotaku.twidere.util.*
import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener
2017-04-22 16:14:40 +02:00
class UserProfileEditorFragment : BaseFragment(), OnSizeChangedListener,
2016-07-05 15:19:51 +02:00
OnClickListener, LoaderCallbacks<SingleResponse<ParcelableUser>>,
KeyboardShortcutsHandler.TakeAllKeyboardShortcut {
2016-07-02 05:54:53 +02:00
2016-07-06 03:18:12 +02:00
private var currentTask: AbstractTask<*, *, UserProfileEditorFragment>? = null
2016-07-02 05:54:53 +02:00
private val accountKey: UserKey
2020-01-26 08:35:15 +01:00
get() = arguments?.getParcelable(EXTRA_ACCOUNT_KEY)!!
2016-07-02 05:54:53 +02:00
private var user: ParcelableUser? = null
2017-04-22 16:14:40 +02:00
private var account: AccountDetails? = null
2016-07-02 05:54:53 +02:00
private var userInfoLoaderInitialized: Boolean = false
private var getUserInfoCalled: Boolean = false
override fun onClick(view: View) {
val user = user ?: return
val account = account ?: return
2016-07-06 03:18:12 +02:00
val task = currentTask
if (task != null && !task.isFinished) return
2016-07-02 05:54:53 +02:00
when (view.id) {
R.id.editProfileImage -> {
2020-01-26 08:35:15 +01:00
val intent = activity?.let {
ThemedMediaPickerActivity.withThemed(it)
.aspectRatio(1, 1)
.maximumSize(512, 512)
.containsVideo(false)
.build()
}
2016-07-02 05:54:53 +02:00
startActivityForResult(intent, REQUEST_UPLOAD_PROFILE_IMAGE)
}
R.id.editProfileBanner -> {
2020-01-26 08:35:15 +01:00
val builder = activity?.let {
ThemedMediaPickerActivity.withThemed(it)
.aspectRatio(3, 1)
.maximumSize(1500, 500)
.containsVideo(false)
}
if (account.type == AccountType.TWITTER) {
2020-01-26 08:35:15 +01:00
builder?.addEntry(getString(R.string.remove), "remove_banner", RESULT_REMOVE_BANNER)
}
2020-01-26 08:35:15 +01:00
startActivityForResult(builder?.build(), REQUEST_UPLOAD_PROFILE_BANNER_IMAGE)
2016-07-02 05:54:53 +02:00
}
R.id.editProfileBackground -> {
2020-01-26 08:35:15 +01:00
val intent = activity?.let {
ThemedMediaPickerActivity.withThemed(it)
.containsVideo(false)
.build()
}
2016-07-02 05:54:53 +02:00
startActivityForResult(intent, REQUEST_UPLOAD_PROFILE_BACKGROUND_IMAGE)
}
R.id.setLinkColor -> {
val intent = Intent(activity, ColorPickerDialogActivity::class.java)
intent.putExtra(EXTRA_COLOR, user.link_color)
intent.putExtra(EXTRA_ALPHA_SLIDER, false)
startActivityForResult(intent, REQUEST_PICK_LINK_COLOR)
}
R.id.setBackgroundColor -> {
val intent = Intent(activity, ColorPickerDialogActivity::class.java)
intent.putExtra(EXTRA_COLOR, user.background_color)
intent.putExtra(EXTRA_ALPHA_SLIDER, false)
startActivityForResult(intent, REQUEST_PICK_BACKGROUND_COLOR)
}
}
}
2016-07-05 15:19:51 +02:00
override fun onCreateLoader(id: Int, args: Bundle?): Loader<SingleResponse<ParcelableUser>> {
progressContainer.visibility = View.VISIBLE
editProfileContent.visibility = View.GONE
return ParcelableUserLoader(requireActivity(), accountKey, accountKey, null, arguments,
omitIntentExtra = false,
loadFromCache = false
)
2016-07-02 05:54:53 +02:00
}
override fun onLoadFinished(loader: Loader<SingleResponse<ParcelableUser>>,
2020-01-26 08:35:15 +01:00
data: SingleResponse<ParcelableUser>) {
2017-04-22 16:14:40 +02:00
val user = data.data ?: this.user ?: run {
activity?.finish()
return
2016-07-02 05:54:53 +02:00
}
2017-04-22 16:14:40 +02:00
displayUser(user, data.extras.getParcelable(EXTRA_ACCOUNT))
2016-07-02 05:54:53 +02:00
}
override fun onLoaderReset(loader: Loader<SingleResponse<ParcelableUser>>) {
}
2017-04-12 10:17:20 +02:00
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_profile_editor, menu)
2016-07-02 05:54:53 +02:00
}
2016-07-06 03:18:12 +02:00
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
2016-07-02 05:54:53 +02:00
R.id.save -> {
2016-07-06 03:18:12 +02:00
val name = ParseUtils.parseString(editName.text)
2016-07-02 05:54:53 +02:00
val url = ParseUtils.parseString(editUrl.text)
2016-07-06 03:18:12 +02:00
val location = ParseUtils.parseString(editLocation.text)
val description = ParseUtils.parseString(editDescription.text)
val linkColor = linkColor.color
val backgroundColor = backgroundColor.color
2017-04-20 16:18:45 +02:00
val task = UpdateProfileTaskInternal(this, accountKey, user, name, url, location,
2016-07-02 05:54:53 +02:00
description, linkColor, backgroundColor)
TaskStarter.execute(task)
2016-07-06 03:18:12 +02:00
this.currentTask = task
2016-07-02 05:54:53 +02:00
return true
}
}
return super.onOptionsItemSelected(item)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
if (!Utils.isMyAccount(requireActivity(), accountKey)) {
2020-01-26 08:35:15 +01:00
activity?.finish()
2016-07-02 05:54:53 +02:00
return
}
val lengthChecker = TwitterValidatorMETLengthChecker(Validator())
2016-07-02 05:54:53 +02:00
2016-07-06 03:18:12 +02:00
editDescription.setLengthChecker(lengthChecker)
2016-07-02 05:54:53 +02:00
2016-07-06 03:18:12 +02:00
profileImage.setOnClickListener(this)
profileBanner.setOnClickListener(this)
profileBackground.setOnClickListener(this)
2016-07-02 05:54:53 +02:00
2016-07-06 03:18:12 +02:00
editProfileImage.setOnClickListener(this)
editProfileBanner.setOnClickListener(this)
editProfileBackground.setOnClickListener(this)
2016-07-02 05:54:53 +02:00
2016-07-06 03:18:12 +02:00
setLinkColor.setOnClickListener(this)
setBackgroundColor.setOnClickListener(this)
2016-07-02 05:54:53 +02:00
2017-04-22 16:14:40 +02:00
val savedUser = savedInstanceState?.getParcelable<ParcelableUser?>(EXTRA_USER)
val savedAccount = savedInstanceState?.getParcelable<AccountDetails?>(EXTRA_ACCOUNT)
if (savedInstanceState != null && savedUser != null && savedAccount != null) {
displayUser(savedUser, savedAccount)
editName.setText(savedInstanceState.getString(EXTRA_NAME, savedUser.name))
editLocation.setText(savedInstanceState.getString(EXTRA_LOCATION, savedUser.location))
editDescription.setText(savedInstanceState.getString(EXTRA_DESCRIPTION,
ParcelableUserUtils.getExpandedDescription(savedUser)))
editUrl.setText(savedInstanceState.getString(EXTRA_URL, savedUser.url_expanded))
2016-07-02 05:54:53 +02:00
} else {
getUserInfo()
}
}
2016-07-06 03:18:12 +02:00
override fun onSaveInstanceState(outState: Bundle) {
2016-07-02 05:54:53 +02:00
super.onSaveInstanceState(outState)
2016-07-06 03:18:12 +02:00
outState.putParcelable(EXTRA_USER, user)
2017-04-22 16:14:40 +02:00
outState.putParcelable(EXTRA_ACCOUNT, account)
2016-07-06 03:18:12 +02:00
outState.putString(EXTRA_NAME, ParseUtils.parseString(editName.text))
outState.putString(EXTRA_DESCRIPTION, ParseUtils.parseString(editDescription.text))
outState.putString(EXTRA_LOCATION, ParseUtils.parseString(editLocation.text))
outState.putString(EXTRA_URL, ParseUtils.parseString(editUrl.text))
2016-07-02 05:54:53 +02:00
}
override fun onSizeChanged(view: View, w: Int, h: Int, oldw: Int, oldh: Int) {
}
2016-07-06 03:18:12 +02:00
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_user_profile_editor, container, false)
2016-07-02 05:54:53 +02:00
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
2016-07-06 03:18:12 +02:00
if (resultCode == FragmentActivity.RESULT_CANCELED || data == null) return
2016-07-02 05:54:53 +02:00
when (requestCode) {
REQUEST_UPLOAD_PROFILE_BANNER_IMAGE -> {
2016-07-06 03:18:12 +02:00
val task = currentTask
if (task != null && !task.isFinished) return
2020-06-08 23:19:10 +02:00
currentTask = if (resultCode == RESULT_REMOVE_BANNER) {
context?.let { RemoveProfileBannerTaskInternal(it, accountKey) }
2016-07-02 05:54:53 +02:00
} else {
2020-06-08 23:19:10 +02:00
UpdateProfileBannerImageTaskInternal(this, accountKey,
data.data!!, true)
2016-07-02 05:54:53 +02:00
}
}
REQUEST_UPLOAD_PROFILE_BACKGROUND_IMAGE -> {
2016-07-06 03:18:12 +02:00
val task = currentTask
if (task != null && !task.isFinished) return
2017-04-20 14:04:37 +02:00
currentTask = UpdateProfileBackgroundImageTaskInternal(this, accountKey,
data.data!!, tile = false, deleteImage = true
)
2016-07-02 05:54:53 +02:00
}
REQUEST_UPLOAD_PROFILE_IMAGE -> {
2016-07-06 03:18:12 +02:00
val task = currentTask
if (task != null && !task.isFinished) return
2017-04-20 14:04:37 +02:00
currentTask = UpdateProfileImageTaskInternal(this, accountKey,
2019-10-24 17:52:11 +02:00
data.data!!, true)
2016-07-02 05:54:53 +02:00
}
REQUEST_PICK_LINK_COLOR -> {
2016-07-08 06:46:54 +02:00
if (resultCode == Activity.RESULT_OK) {
2016-07-06 03:18:12 +02:00
linkColor.color = data.getIntExtra(EXTRA_COLOR, 0)
2016-07-02 05:54:53 +02:00
}
}
REQUEST_PICK_BACKGROUND_COLOR -> {
2016-07-08 06:46:54 +02:00
if (resultCode == Activity.RESULT_OK) {
2016-07-06 03:18:12 +02:00
backgroundColor.color = data.getIntExtra(EXTRA_COLOR, 0)
2016-07-02 05:54:53 +02:00
}
}
}
2016-07-06 03:18:12 +02:00
executeAfterFragmentResumed {
val task = currentTask
if (task != null && !task.isFinished) {
TaskStarter.execute(task)
}
}
2016-07-02 05:54:53 +02:00
}
2017-04-22 16:14:40 +02:00
private fun displayUser(user: ParcelableUser?, account: AccountDetails?) {
2020-01-26 08:35:15 +01:00
val context = context ?: return
2016-07-02 05:54:53 +02:00
if (!getUserInfoCalled) return
2020-01-26 08:35:15 +01:00
if (isDetached || (activity?.isFinishing != false)) return
2016-07-02 05:54:53 +02:00
getUserInfoCalled = false
this.user = user
2017-04-22 16:14:40 +02:00
this.account = account
if (user != null && account != null) {
2016-07-06 03:18:12 +02:00
progressContainer.visibility = View.GONE
editProfileContent.visibility = View.VISIBLE
2016-07-02 05:54:53 +02:00
editName.setText(user.name)
editDescription.setText(ParcelableUserUtils.getExpandedDescription(user))
editLocation.setText(user.location)
editUrl.setText(if (isEmpty(user.url_expanded)) user.url else user.url_expanded)
2017-03-01 15:12:25 +01:00
2017-05-10 12:53:29 +02:00
requestManager.loadProfileImage(context, user, 0).into(profileImage)
requestManager.loadProfileBanner(context, user, resources.displayMetrics.widthPixels)
.into(profileBanner)
requestManager.load(user.profile_background_url).into(profileBackground)
2017-03-01 15:12:25 +01:00
2016-07-06 03:18:12 +02:00
linkColor.color = user.link_color
backgroundColor.color = user.background_color
2017-04-22 16:14:40 +02:00
var canEditUrl = false
var canEditLocation = false
var canEditBanner = false
var canEditBackground = false
var canEditLinkColor = false
var canEditBackgroundColor = false
when (account.type) {
AccountType.TWITTER -> {
canEditUrl = true
canEditLocation = true
canEditBanner = true
canEditBackground = true
canEditLinkColor = true
canEditBackgroundColor = true
}
AccountType.MASTODON -> {
canEditBanner = true
}
AccountType.FANFOU -> {
canEditUrl = true
canEditLocation = true
canEditBackground = true
canEditLinkColor = true
canEditBackgroundColor = true
}
2016-07-02 05:54:53 +02:00
}
2017-04-22 16:14:40 +02:00
editProfileBanner.visibility = if (canEditBanner) View.VISIBLE else View.GONE
editProfileBackground.visibility = if (canEditBackground) View.VISIBLE else View.GONE
editUrl.visibility = if (canEditUrl) View.VISIBLE else View.GONE
editLocation.visibility = if (canEditLocation) View.VISIBLE else View.GONE
setLinkColor.visibility = if (canEditLinkColor) View.VISIBLE else View.GONE
setBackgroundColor.visibility = if (canEditBackgroundColor) View.VISIBLE else View.GONE
2016-07-02 05:54:53 +02:00
} else {
2016-07-06 03:18:12 +02:00
progressContainer.visibility = View.GONE
editProfileContent.visibility = View.GONE
2016-07-02 05:54:53 +02:00
}
}
private fun getUserInfo() {
if (activity == null || isDetached) return
val lm = loaderManager
lm.destroyLoader(LOADER_ID_USER)
getUserInfoCalled = true
if (userInfoLoaderInitialized) {
lm.restartLoader(LOADER_ID_USER, null, this)
} else {
lm.initLoader(LOADER_ID_USER, null, this)
userInfoLoaderInitialized = true
}
}
private fun dismissDialogFragment(tag: String) {
executeAfterFragmentResumed {
val fm = childFragmentManager
val f = fm.findFragmentByTag(tag)
if (f is DialogFragment) {
f.dismiss()
}
}
}
private fun setUpdateState(start: Boolean) {
if (!start) {
dismissDialogFragment(UPDATE_PROFILE_DIALOG_FRAGMENT_TAG)
return
}
executeAfterFragmentResumed {
val fm = childFragmentManager
val df = ProgressDialogFragment()
df.show(fm, UPDATE_PROFILE_DIALOG_FRAGMENT_TAG)
df.isCancelable = false
}
}
internal class UpdateProfileTaskInternal(
2017-04-20 16:18:45 +02:00
fragment: UserProfileEditorFragment,
accountKey: UserKey,
2016-07-02 05:54:53 +02:00
private val original: ParcelableUser?,
private val name: String,
private val url: String,
private val location: String,
private val description: String,
private val linkColor: Int,
private val backgroundColor: Int
2017-04-20 16:18:45 +02:00
) : AbsAccountRequestTask<Any?, Pair<ParcelableUser, AccountDetails>,
UserProfileEditorFragment>(fragment.requireContext(), accountKey) {
2016-07-02 05:54:53 +02:00
2017-04-20 16:18:45 +02:00
init {
this.callback = fragment
2016-07-02 05:54:53 +02:00
}
2017-04-20 16:18:45 +02:00
override fun onExecute(account: AccountDetails, params: Any?): Pair<ParcelableUser, AccountDetails> {
val orig = this.original
if (orig != null && !orig.isProfileChanged()) {
return Pair(orig, account)
2016-07-02 05:54:53 +02:00
}
2017-04-22 16:14:40 +02:00
return Pair(when (account.type) {
AccountType.MASTODON -> updateMastodonProfile(account)
else -> updateMicroBlogProfile(account)
}, account)
}
override fun onSucceed(callback: UserProfileEditorFragment?, result: Pair<ParcelableUser, AccountDetails>) {
if (callback == null) return
promiseOnUi {
val context = this.callback?.context ?: return@promiseOnUi
val (user, account) = result
val task = UpdateAccountInfoTask(context)
task.params = Pair(account, user)
TaskStarter.execute(task)
} and callback.executeAfterFragmentResumed { fragment ->
fragment.childFragmentManager.dismissDialogFragment(DIALOG_FRAGMENT_TAG)
2020-01-26 08:35:15 +01:00
fragment.activity?.finish()
2017-04-22 16:14:40 +02:00
}
}
override fun beforeExecute() {
super.beforeExecute()
callback?.executeAfterFragmentResumed { fragment ->
val df = ProgressDialogFragment.show(fragment.childFragmentManager, DIALOG_FRAGMENT_TAG)
df.isCancelable = false
}
}
private fun updateMicroBlogProfile(account: AccountDetails): ParcelableUser {
val microBlog = account.newMicroBlogInstance(context = context, cls = MicroBlog::class.java)
2017-04-20 16:18:45 +02:00
val profileUpdate = ProfileUpdate()
profileUpdate.name(HtmlEscapeHelper.escapeBasic(name))
profileUpdate.location(HtmlEscapeHelper.escapeBasic(location))
profileUpdate.description(HtmlEscapeHelper.escapeBasic(description))
profileUpdate.url(url)
profileUpdate.linkColor(linkColor)
profileUpdate.backgroundColor(backgroundColor)
val profileImageSize = context.getString(R.string.profile_image_size)
2017-04-22 16:14:40 +02:00
return microBlog.updateProfile(profileUpdate).toParcelable(account,
profileImageSize = profileImageSize)
}
2016-07-02 05:54:53 +02:00
2017-04-22 16:14:40 +02:00
private fun updateMastodonProfile(account: AccountDetails): ParcelableUser {
val mastodon = account.newMicroBlogInstance(context = context, cls = Mastodon::class.java)
val accountUpdate = AccountUpdate()
accountUpdate.displayName(name)
accountUpdate.note(HtmlEscapeHelper.escapeBasic(description))
return mastodon.updateCredentials(accountUpdate).toParcelable(account)
2017-04-20 16:18:45 +02:00
}
private fun ParcelableUser.isProfileChanged(): Boolean {
if (linkColor != link_color) return true
if (backgroundColor != background_color) return true
if (!TextUtils.equals(this@UpdateProfileTaskInternal.name, name)) return true
if (!TextUtils.equals(description, ParcelableUserUtils.getExpandedDescription(this)))
return true
if (!TextUtils.equals(this@UpdateProfileTaskInternal.location, location)) return true
if (!TextUtils.equals(this@UpdateProfileTaskInternal.url, if (isEmpty(url_expanded)) url else url_expanded))
return true
return false
}
2016-07-02 05:54:53 +02:00
companion object {
2020-06-08 23:11:06 +02:00
private const val DIALOG_FRAGMENT_TAG = "updating_user_profile"
2016-07-02 05:54:53 +02:00
}
}
2017-04-20 14:04:37 +02:00
internal class RemoveProfileBannerTaskInternal(
context: Context,
accountKey: UserKey
) : AbsAccountRequestTask<Any?, Boolean, UserProfileEditorFragment>(context, accountKey) {
override fun onExecute(account: AccountDetails, params: Any?): Boolean {
return account.newMicroBlogInstance(context, MicroBlog::class.java)
.removeProfileBannerImage().isSuccessful
2016-07-02 05:54:53 +02:00
}
2017-04-20 14:04:37 +02:00
override fun onSucceed(callback: UserProfileEditorFragment?, result: Boolean) {
if (callback == null) return
val context = callback.context
callback.getUserInfo()
Toast.makeText(context, R.string.message_toast_profile_banner_image_updated,
Toast.LENGTH_SHORT).show()
2016-07-02 05:54:53 +02:00
}
override fun beforeExecute() {
super.beforeExecute()
2017-04-20 14:04:37 +02:00
callback?.setUpdateState(true)
2016-07-02 05:54:53 +02:00
}
}
2017-04-20 14:04:37 +02:00
private class UpdateProfileBannerImageTaskInternal(
fragment: UserProfileEditorFragment,
accountKey: UserKey,
imageUri: Uri,
deleteImage: Boolean
) : UpdateProfileBannerImageTask<UserProfileEditorFragment>(fragment.requireContext(), accountKey, imageUri, deleteImage) {
2016-07-02 05:54:53 +02:00
2017-04-20 14:04:37 +02:00
init {
callback = fragment
}
override fun afterExecute(callback: UserProfileEditorFragment?, result: ParcelableUser?, exception: MicroBlogException?) {
callback?.setUpdateState(false)
callback?.getUserInfo()
2016-07-02 05:54:53 +02:00
}
override fun beforeExecute() {
2017-04-20 14:04:37 +02:00
callback?.setUpdateState(true)
2016-07-02 05:54:53 +02:00
}
}
2017-04-20 14:04:37 +02:00
private class UpdateProfileBackgroundImageTaskInternal(
fragment: UserProfileEditorFragment,
2016-12-09 03:02:41 +01:00
accountKey: UserKey,
imageUri: Uri,
tile: Boolean,
deleteImage: Boolean
) : UpdateProfileBackgroundImageTask<UserProfileEditorFragment>(fragment.requireContext(), accountKey, imageUri,
2016-12-09 03:02:41 +01:00
tile, deleteImage) {
2017-04-20 14:04:37 +02:00
init {
callback = fragment
}
override fun afterExecute(callback: UserProfileEditorFragment?, result: ParcelableUser?, exception: MicroBlogException?) {
super.afterExecute(callback, result, exception)
callback?.setUpdateState(false)
callback?.getUserInfo()
2016-07-02 05:54:53 +02:00
}
override fun beforeExecute() {
super.beforeExecute()
2017-04-20 14:04:37 +02:00
callback?.setUpdateState(true)
2016-07-02 05:54:53 +02:00
}
}
2017-04-20 14:04:37 +02:00
private class UpdateProfileImageTaskInternal(
fragment: UserProfileEditorFragment,
2016-12-09 03:02:41 +01:00
accountKey: UserKey,
imageUri: Uri,
deleteImage: Boolean
) : UpdateProfileImageTask<UserProfileEditorFragment>(fragment.requireContext(), accountKey, imageUri, deleteImage) {
2016-07-02 05:54:53 +02:00
2017-04-20 14:04:37 +02:00
init {
callback = fragment
}
override fun afterExecute(callback: UserProfileEditorFragment?, result: ParcelableUser?, exception: MicroBlogException?) {
super.afterExecute(callback, result, exception)
callback?.setUpdateState(false)
2017-04-22 16:14:40 +02:00
callback?.getUserInfo()
2016-07-02 05:54:53 +02:00
}
override fun beforeExecute() {
super.beforeExecute()
2017-04-20 14:04:37 +02:00
callback?.setUpdateState(true)
2016-07-02 05:54:53 +02:00
}
}
companion object {
2020-06-08 23:11:06 +02:00
private const val LOADER_ID_USER = 1
2016-07-02 05:54:53 +02:00
2020-06-08 23:11:06 +02:00
private const val REQUEST_UPLOAD_PROFILE_IMAGE = 1
private const val REQUEST_UPLOAD_PROFILE_BANNER_IMAGE = 2
private const val REQUEST_UPLOAD_PROFILE_BACKGROUND_IMAGE = 3
private const val REQUEST_PICK_LINK_COLOR = 11
private const val REQUEST_PICK_BACKGROUND_COLOR = 12
2016-07-02 05:54:53 +02:00
2020-06-08 23:11:06 +02:00
private const val RESULT_REMOVE_BANNER = 101
private const val UPDATE_PROFILE_DIALOG_FRAGMENT_TAG = "update_profile"
2016-07-02 05:54:53 +02:00
}
}