2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.ContentValues
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
import android.media.RingtoneManager
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.AsyncTask
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Handler
|
|
|
|
import android.provider.MediaStore
|
|
|
|
import android.provider.Settings
|
2018-08-04 20:56:51 +02:00
|
|
|
import android.text.Editable
|
2018-09-05 16:03:26 +02:00
|
|
|
import android.text.SpannableString
|
2018-08-04 20:56:51 +02:00
|
|
|
import android.text.TextWatcher
|
2018-01-04 19:52:25 +01:00
|
|
|
import android.view.View
|
2018-08-20 19:37:42 +02:00
|
|
|
import android.widget.*
|
2019-08-24 05:35:22 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
|
import androidx.core.content.ContextCompat
|
2019-01-16 13:33:07 +01:00
|
|
|
import jp.juggler.subwaytooter.Styler.defaultColorIcon
|
2018-05-11 15:42:54 +02:00
|
|
|
import jp.juggler.subwaytooter.api.*
|
2018-09-05 16:03:26 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.dialog.ActionsDialog
|
2018-02-12 14:56:37 +01:00
|
|
|
import jp.juggler.subwaytooter.dialog.ProgressDialogEx
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.table.AcctColor
|
|
|
|
import jp.juggler.subwaytooter.table.SavedAccount
|
2018-01-21 13:46:36 +01:00
|
|
|
import jp.juggler.subwaytooter.util.*
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.view.MyNetworkImageView
|
2018-12-01 00:02:18 +01:00
|
|
|
import jp.juggler.util.*
|
2018-02-12 14:56:37 +01:00
|
|
|
import okhttp3.MediaType
|
2019-08-24 05:35:22 +02:00
|
|
|
import okhttp3.MediaType.Companion.toMediaType
|
2018-02-12 14:56:37 +01:00
|
|
|
import okhttp3.MultipartBody
|
2018-01-04 19:52:25 +01:00
|
|
|
import okhttp3.RequestBody
|
2018-02-12 14:56:37 +01:00
|
|
|
import okio.BufferedSink
|
2019-01-21 00:00:59 +01:00
|
|
|
import org.jetbrains.anko.backgroundColor
|
|
|
|
import org.jetbrains.anko.textColor
|
2018-08-20 19:37:42 +02:00
|
|
|
import org.json.JSONObject
|
|
|
|
import java.io.*
|
2019-08-24 05:35:22 +02:00
|
|
|
import kotlin.math.max
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
class ActAccountSetting
|
|
|
|
: AppCompatActivity(), View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
companion object {
|
|
|
|
|
|
|
|
internal val log = LogCategory("ActAccountSetting")
|
|
|
|
|
|
|
|
internal const val KEY_ACCOUNT_DB_ID = "account_db_id"
|
|
|
|
|
|
|
|
internal const val REQUEST_CODE_ACCT_CUSTOMIZE = 1
|
|
|
|
internal const val REQUEST_CODE_NOTIFICATION_SOUND = 2
|
|
|
|
private const val REQUEST_CODE_AVATAR_ATTACHMENT = 3
|
|
|
|
private const val REQUEST_CODE_HEADER_ATTACHMENT = 4
|
|
|
|
private const val REQUEST_CODE_AVATAR_CAMERA = 5
|
|
|
|
private const val REQUEST_CODE_HEADER_CAMERA = 6
|
|
|
|
|
|
|
|
internal const val RESULT_INPUT_ACCESS_TOKEN = Activity.RESULT_FIRST_USER + 10
|
|
|
|
internal const val EXTRA_DB_ID = "db_id"
|
|
|
|
|
|
|
|
internal const val max_length_display_name = 30
|
|
|
|
internal const val max_length_note = 160
|
2018-05-04 15:35:01 +02:00
|
|
|
internal const val max_length_fields = 255
|
2018-01-21 13:46:36 +01:00
|
|
|
|
|
|
|
private const val PERMISSION_REQUEST_AVATAR = 1
|
|
|
|
private const val PERMISSION_REQUEST_HEADER = 2
|
|
|
|
|
|
|
|
internal const val MIME_TYPE_JPEG = "image/jpeg"
|
|
|
|
internal const val MIME_TYPE_PNG = "image/png"
|
|
|
|
|
|
|
|
fun open(activity : Activity, ai : SavedAccount, requestCode : Int) {
|
|
|
|
val intent = Intent(activity, ActAccountSetting::class.java)
|
|
|
|
intent.putExtra(KEY_ACCOUNT_DB_ID, ai.db_id)
|
|
|
|
activity.startActivityForResult(intent, requestCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal lateinit var account : SavedAccount
|
|
|
|
internal lateinit var pref : SharedPreferences
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
private lateinit var tvInstance : TextView
|
|
|
|
private lateinit var tvUser : TextView
|
2019-06-04 01:24:54 +02:00
|
|
|
private lateinit var btnAccessToken : Button
|
|
|
|
private lateinit var btnInputAccessToken : Button
|
|
|
|
private lateinit var btnAccountRemove : Button
|
|
|
|
private lateinit var btnLoadPreference : Button
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var btnVisibility : Button
|
2019-06-04 01:24:54 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var swNSFWOpen : Switch
|
|
|
|
private lateinit var swDontShowTimeout : Switch
|
2019-06-04 01:24:54 +02:00
|
|
|
private lateinit var swExpandCW : Switch
|
|
|
|
private lateinit var swMarkSensitive : Switch
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var btnOpenBrowser : Button
|
2018-05-12 10:17:12 +02:00
|
|
|
private lateinit var btnPushSubscription : Button
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var cbNotificationMention : CheckBox
|
|
|
|
private lateinit var cbNotificationBoost : CheckBox
|
|
|
|
private lateinit var cbNotificationFavourite : CheckBox
|
|
|
|
private lateinit var cbNotificationFollow : CheckBox
|
2018-08-30 08:51:32 +02:00
|
|
|
private lateinit var cbNotificationReaction : CheckBox
|
|
|
|
private lateinit var cbNotificationVote : CheckBox
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
private lateinit var cbConfirmFollow : CheckBox
|
|
|
|
private lateinit var cbConfirmFollowLockedUser : CheckBox
|
|
|
|
private lateinit var cbConfirmUnfollow : CheckBox
|
|
|
|
private lateinit var cbConfirmBoost : CheckBox
|
2018-04-17 14:41:22 +02:00
|
|
|
private lateinit var cbConfirmFavourite : CheckBox
|
2018-04-20 12:43:09 +02:00
|
|
|
private lateinit var cbConfirmUnboost : CheckBox
|
|
|
|
private lateinit var cbConfirmUnfavourite : CheckBox
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var cbConfirmToot : CheckBox
|
|
|
|
|
|
|
|
private lateinit var tvUserCustom : TextView
|
|
|
|
private lateinit var btnUserCustom : View
|
|
|
|
private lateinit var full_acct : String
|
|
|
|
|
|
|
|
private lateinit var btnNotificationSoundEdit : Button
|
|
|
|
private lateinit var btnNotificationSoundReset : Button
|
|
|
|
private lateinit var btnNotificationStyleEdit : Button
|
|
|
|
|
|
|
|
private var notification_sound_uri : String? = null
|
|
|
|
|
|
|
|
private lateinit var ivProfileHeader : MyNetworkImageView
|
|
|
|
private lateinit var ivProfileAvatar : MyNetworkImageView
|
|
|
|
private lateinit var btnProfileAvatar : View
|
|
|
|
private lateinit var btnProfileHeader : View
|
|
|
|
private lateinit var etDisplayName : EditText
|
|
|
|
private lateinit var btnDisplayName : View
|
|
|
|
private lateinit var etNote : EditText
|
2018-03-10 01:28:53 +01:00
|
|
|
private lateinit var cbLocked : CheckBox
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var btnNote : View
|
2018-12-02 11:25:00 +01:00
|
|
|
private lateinit var etDefaultText : EditText
|
2018-08-04 20:56:51 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private lateinit var name_invalidator : NetworkEmojiInvalidator
|
|
|
|
private lateinit var note_invalidator : NetworkEmojiInvalidator
|
2018-08-04 20:56:51 +02:00
|
|
|
private lateinit var default_text_invalidator : NetworkEmojiInvalidator
|
2018-01-21 13:46:36 +01:00
|
|
|
internal lateinit var handler : Handler
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
internal var loading = false
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
private lateinit var listEtFieldName : List<EditText>
|
|
|
|
private lateinit var listEtFieldValue : List<EditText>
|
|
|
|
private lateinit var listFieldNameInvalidator : List<NetworkEmojiInvalidator>
|
|
|
|
private lateinit var listFieldValueInvalidator : List<NetworkEmojiInvalidator>
|
|
|
|
private lateinit var btnFields : View
|
|
|
|
|
2019-08-12 05:32:39 +02:00
|
|
|
private lateinit var etMaxTootChars : EditText
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
internal var visibility = TootVisibility.Public
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
private var uriCameraImage : Uri? = null
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState : Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
App1.setActivityTheme(this, false)
|
|
|
|
this.pref = App1.pref
|
|
|
|
|
|
|
|
initUI()
|
|
|
|
|
|
|
|
val a = SavedAccount.loadAccount(this, intent.getLongExtra(KEY_ACCOUNT_DB_ID, - 1L))
|
2018-01-21 13:46:36 +01:00
|
|
|
if(a == null) {
|
2018-01-10 16:47:35 +01:00
|
|
|
finish()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.account = a
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
loadUIFromData(account)
|
|
|
|
|
|
|
|
initializeProfile()
|
|
|
|
|
|
|
|
btnOpenBrowser.text = getString(R.string.open_instance_website, account.host)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
PollingWorker.queueUpdateNotification(this)
|
|
|
|
super.onStop()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode : Int, resultCode : Int, data : Intent?) {
|
|
|
|
when(requestCode) {
|
|
|
|
REQUEST_CODE_ACCT_CUSTOMIZE -> {
|
|
|
|
if(resultCode == Activity.RESULT_OK) {
|
|
|
|
showAcctColor()
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
REQUEST_CODE_NOTIFICATION_SOUND -> {
|
2018-01-10 16:47:35 +01:00
|
|
|
if(resultCode == Activity.RESULT_OK) {
|
2018-01-04 19:52:25 +01:00
|
|
|
// RINGTONE_PICKERからの選択されたデータを取得する
|
2018-01-21 13:46:36 +01:00
|
|
|
val uri = data?.extras?.get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
|
2018-01-04 19:52:25 +01:00
|
|
|
if(uri is Uri) {
|
|
|
|
notification_sound_uri = uri.toString()
|
|
|
|
saveUIToData()
|
|
|
|
// Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), uri);
|
|
|
|
// TextView ringView = (TextView) findViewById(R.id.ringtone);
|
|
|
|
// ringView.setText(ringtone.getTitle(getApplicationContext()));
|
|
|
|
// ringtone.setStreamType(AudioManager.STREAM_ALARM);
|
|
|
|
// ringtone.play();
|
|
|
|
// SystemClock.sleep(1000);
|
|
|
|
// ringtone.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
REQUEST_CODE_AVATAR_ATTACHMENT, REQUEST_CODE_HEADER_ATTACHMENT -> {
|
2018-12-02 11:25:00 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
if(resultCode == Activity.RESULT_OK && data != null) {
|
2018-12-02 11:25:00 +01:00
|
|
|
data.handleGetContentResult(contentResolver).firstOrNull()?.let {
|
2018-01-21 13:46:36 +01:00
|
|
|
addAttachment(
|
|
|
|
requestCode,
|
2018-11-28 20:57:50 +01:00
|
|
|
it.uri,
|
2019-01-21 00:00:59 +01:00
|
|
|
it.mimeType?.notEmpty() ?: contentResolver.getType(it.uri)
|
2018-01-21 13:46:36 +01:00
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
REQUEST_CODE_AVATAR_CAMERA, REQUEST_CODE_HEADER_CAMERA -> {
|
|
|
|
|
|
|
|
if(resultCode != Activity.RESULT_OK) {
|
|
|
|
// 失敗したら DBからデータを削除
|
2018-01-10 16:47:35 +01:00
|
|
|
val uriCameraImage = this@ActAccountSetting.uriCameraImage
|
2018-01-04 19:52:25 +01:00
|
|
|
if(uriCameraImage != null) {
|
2018-01-21 13:46:36 +01:00
|
|
|
contentResolver.delete(uriCameraImage, null, null)
|
2018-01-10 16:47:35 +01:00
|
|
|
this@ActAccountSetting.uriCameraImage = null
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 画像のURL
|
2018-01-10 16:47:35 +01:00
|
|
|
val uri = data?.data ?: uriCameraImage
|
2018-01-04 19:52:25 +01:00
|
|
|
if(uri != null) {
|
|
|
|
val type = contentResolver.getType(uri)
|
|
|
|
addAttachment(requestCode, uri, type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
else -> super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
var density : Float = 1f
|
2018-01-18 08:53:32 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private fun initUI() {
|
2018-01-18 08:53:32 +01:00
|
|
|
this.density = resources.displayMetrics.density
|
2018-01-04 19:52:25 +01:00
|
|
|
this.handler = Handler()
|
|
|
|
setContentView(R.layout.act_account_setting)
|
2019-08-31 16:33:13 +02:00
|
|
|
App1.initEdgeToEdge(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-09-12 13:59:33 +02:00
|
|
|
val root : View = findViewById(R.id.svContent)
|
2019-07-25 00:01:53 +02:00
|
|
|
|
|
|
|
Styler.fixHorizontalPadding(root)
|
2019-09-12 13:59:33 +02:00
|
|
|
|
|
|
|
ActAppSettingChild.setSwitchColor(this, pref, root)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
tvInstance = findViewById(R.id.tvInstance)
|
|
|
|
tvUser = findViewById(R.id.tvUser)
|
|
|
|
btnAccessToken = findViewById(R.id.btnAccessToken)
|
|
|
|
btnInputAccessToken = findViewById(R.id.btnInputAccessToken)
|
|
|
|
btnAccountRemove = findViewById(R.id.btnAccountRemove)
|
2019-06-04 01:24:54 +02:00
|
|
|
btnLoadPreference = findViewById(R.id.btnLoadPreference)
|
2018-01-04 19:52:25 +01:00
|
|
|
btnVisibility = findViewById(R.id.btnVisibility)
|
|
|
|
swNSFWOpen = findViewById(R.id.swNSFWOpen)
|
|
|
|
swDontShowTimeout = findViewById(R.id.swDontShowTimeout)
|
2019-06-04 01:24:54 +02:00
|
|
|
swExpandCW = findViewById(R.id.swExpandCW)
|
|
|
|
swMarkSensitive = findViewById(R.id.swMarkSensitive)
|
2018-01-04 19:52:25 +01:00
|
|
|
btnOpenBrowser = findViewById(R.id.btnOpenBrowser)
|
2018-05-12 10:17:12 +02:00
|
|
|
btnPushSubscription = findViewById(R.id.btnPushSubscription)
|
2018-01-04 19:52:25 +01:00
|
|
|
cbNotificationMention = findViewById(R.id.cbNotificationMention)
|
|
|
|
cbNotificationBoost = findViewById(R.id.cbNotificationBoost)
|
|
|
|
cbNotificationFavourite = findViewById(R.id.cbNotificationFavourite)
|
|
|
|
cbNotificationFollow = findViewById(R.id.cbNotificationFollow)
|
2018-08-30 08:51:32 +02:00
|
|
|
cbNotificationReaction = findViewById(R.id.cbNotificationReaction)
|
|
|
|
cbNotificationVote = findViewById(R.id.cbNotificationVote)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
cbConfirmFollow = findViewById(R.id.cbConfirmFollow)
|
|
|
|
cbConfirmFollowLockedUser = findViewById(R.id.cbConfirmFollowLockedUser)
|
|
|
|
cbConfirmUnfollow = findViewById(R.id.cbConfirmUnfollow)
|
|
|
|
cbConfirmBoost = findViewById(R.id.cbConfirmBoost)
|
2018-04-17 14:41:22 +02:00
|
|
|
cbConfirmFavourite = findViewById(R.id.cbConfirmFavourite)
|
2018-04-20 12:43:09 +02:00
|
|
|
cbConfirmUnboost = findViewById(R.id.cbConfirmUnboost)
|
|
|
|
cbConfirmUnfavourite = findViewById(R.id.cbConfirmUnfavourite)
|
2018-01-04 19:52:25 +01:00
|
|
|
cbConfirmToot = findViewById(R.id.cbConfirmToot)
|
|
|
|
|
|
|
|
tvUserCustom = findViewById(R.id.tvUserCustom)
|
|
|
|
btnUserCustom = findViewById(R.id.btnUserCustom)
|
|
|
|
|
|
|
|
ivProfileHeader = findViewById(R.id.ivProfileHeader)
|
|
|
|
ivProfileAvatar = findViewById(R.id.ivProfileAvatar)
|
|
|
|
btnProfileAvatar = findViewById(R.id.btnProfileAvatar)
|
|
|
|
btnProfileHeader = findViewById(R.id.btnProfileHeader)
|
|
|
|
etDisplayName = findViewById(R.id.etDisplayName)
|
2018-12-02 11:25:00 +01:00
|
|
|
etDefaultText = findViewById(R.id.etDefaultText)
|
2019-08-12 05:32:39 +02:00
|
|
|
etMaxTootChars = findViewById(R.id.etMaxTootChars)
|
2018-01-04 19:52:25 +01:00
|
|
|
btnDisplayName = findViewById(R.id.btnDisplayName)
|
|
|
|
etNote = findViewById(R.id.etNote)
|
|
|
|
btnNote = findViewById(R.id.btnNote)
|
2018-03-10 01:28:53 +01:00
|
|
|
cbLocked = findViewById(R.id.cbLocked)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
listEtFieldName = arrayOf(
|
|
|
|
R.id.etFieldName1,
|
|
|
|
R.id.etFieldName2,
|
|
|
|
R.id.etFieldName3,
|
|
|
|
R.id.etFieldName4
|
|
|
|
).map { requireNotNull(findViewById<EditText>(it)) }
|
|
|
|
|
|
|
|
listEtFieldValue = arrayOf(
|
|
|
|
R.id.etFieldValue1,
|
|
|
|
R.id.etFieldValue2,
|
|
|
|
R.id.etFieldValue3,
|
|
|
|
R.id.etFieldValue4
|
|
|
|
).map { requireNotNull(findViewById<EditText>(it)) }
|
|
|
|
|
|
|
|
btnFields = findViewById(R.id.btnFields)
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
btnOpenBrowser.setOnClickListener(this)
|
2018-05-12 10:17:12 +02:00
|
|
|
btnPushSubscription.setOnClickListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
btnAccessToken.setOnClickListener(this)
|
|
|
|
btnInputAccessToken.setOnClickListener(this)
|
|
|
|
btnAccountRemove.setOnClickListener(this)
|
2019-06-04 01:24:54 +02:00
|
|
|
btnLoadPreference.setOnClickListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
btnVisibility.setOnClickListener(this)
|
|
|
|
btnUserCustom.setOnClickListener(this)
|
|
|
|
btnProfileAvatar.setOnClickListener(this)
|
|
|
|
btnProfileHeader.setOnClickListener(this)
|
|
|
|
btnDisplayName.setOnClickListener(this)
|
|
|
|
btnNote.setOnClickListener(this)
|
2018-05-04 15:35:01 +02:00
|
|
|
btnFields.setOnClickListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
swNSFWOpen.setOnCheckedChangeListener(this)
|
|
|
|
swDontShowTimeout.setOnCheckedChangeListener(this)
|
2019-06-04 01:24:54 +02:00
|
|
|
swExpandCW.setOnCheckedChangeListener(this)
|
|
|
|
swMarkSensitive.setOnCheckedChangeListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
cbNotificationMention.setOnCheckedChangeListener(this)
|
|
|
|
cbNotificationBoost.setOnCheckedChangeListener(this)
|
|
|
|
cbNotificationFavourite.setOnCheckedChangeListener(this)
|
|
|
|
cbNotificationFollow.setOnCheckedChangeListener(this)
|
2018-08-30 08:51:32 +02:00
|
|
|
cbNotificationReaction.setOnCheckedChangeListener(this)
|
|
|
|
cbNotificationVote.setOnCheckedChangeListener(this)
|
2018-03-10 01:28:53 +01:00
|
|
|
cbLocked.setOnCheckedChangeListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
cbConfirmFollow.setOnCheckedChangeListener(this)
|
|
|
|
cbConfirmFollowLockedUser.setOnCheckedChangeListener(this)
|
|
|
|
cbConfirmUnfollow.setOnCheckedChangeListener(this)
|
|
|
|
cbConfirmBoost.setOnCheckedChangeListener(this)
|
2018-04-17 14:41:22 +02:00
|
|
|
cbConfirmFavourite.setOnCheckedChangeListener(this)
|
2018-04-20 12:43:09 +02:00
|
|
|
cbConfirmUnboost.setOnCheckedChangeListener(this)
|
|
|
|
cbConfirmUnfavourite.setOnCheckedChangeListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
cbConfirmToot.setOnCheckedChangeListener(this)
|
|
|
|
|
|
|
|
btnNotificationSoundEdit = findViewById(R.id.btnNotificationSoundEdit)
|
|
|
|
btnNotificationSoundReset = findViewById(R.id.btnNotificationSoundReset)
|
|
|
|
btnNotificationStyleEdit = findViewById(R.id.btnNotificationStyleEdit)
|
|
|
|
btnNotificationSoundEdit.setOnClickListener(this)
|
|
|
|
btnNotificationSoundReset.setOnClickListener(this)
|
|
|
|
btnNotificationStyleEdit.setOnClickListener(this)
|
|
|
|
|
|
|
|
name_invalidator = NetworkEmojiInvalidator(handler, etDisplayName)
|
|
|
|
note_invalidator = NetworkEmojiInvalidator(handler, etNote)
|
2018-08-04 20:56:51 +02:00
|
|
|
default_text_invalidator = NetworkEmojiInvalidator(handler, etDefaultText)
|
2019-09-12 13:59:33 +02:00
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
listFieldNameInvalidator = listEtFieldName.map {
|
|
|
|
NetworkEmojiInvalidator(handler, it)
|
|
|
|
}
|
|
|
|
|
|
|
|
listFieldValueInvalidator = listEtFieldValue.map {
|
|
|
|
NetworkEmojiInvalidator(handler, it)
|
|
|
|
}
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
etDefaultText.addTextChangedListener(object : TextWatcher {
|
2018-08-04 20:56:51 +02:00
|
|
|
override fun afterTextChanged(s : Editable?) {
|
|
|
|
saveUIToData()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun beforeTextChanged(
|
|
|
|
s : CharSequence?,
|
|
|
|
start : Int,
|
|
|
|
count : Int,
|
|
|
|
after : Int
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onTextChanged(
|
|
|
|
s : CharSequence?,
|
|
|
|
start : Int,
|
|
|
|
before : Int,
|
|
|
|
count : Int
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-08-12 05:32:39 +02:00
|
|
|
etMaxTootChars.addTextChangedListener(object : TextWatcher {
|
|
|
|
override fun beforeTextChanged(
|
|
|
|
s : CharSequence?,
|
|
|
|
start : Int,
|
|
|
|
count : Int,
|
|
|
|
after : Int
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onTextChanged(
|
|
|
|
s : CharSequence?,
|
|
|
|
start : Int,
|
|
|
|
before : Int,
|
|
|
|
count : Int
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun afterTextChanged(s : Editable?) {
|
|
|
|
val num = etMaxTootChars.parseInt()
|
2019-09-12 13:59:33 +02:00
|
|
|
if(num != null && num >= 0) {
|
2019-08-12 05:32:39 +02:00
|
|
|
saveUIToData()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-12 13:59:33 +02:00
|
|
|
private fun EditText.parseInt() : Int? {
|
2019-08-12 05:32:39 +02:00
|
|
|
val sv = this.text?.toString() ?: return null
|
2019-09-12 13:59:33 +02:00
|
|
|
return try {
|
|
|
|
Integer.parseInt(sv, 10)
|
|
|
|
} catch(ex : Throwable) {
|
2019-08-12 05:32:39 +02:00
|
|
|
null
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun loadUIFromData(a : SavedAccount) {
|
|
|
|
|
|
|
|
this.full_acct = a.acct
|
|
|
|
|
|
|
|
tvInstance.text = a.host
|
|
|
|
tvUser.text = a.acct
|
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
this.visibility = a.visibility
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
swNSFWOpen.isChecked = a.dont_hide_nsfw
|
|
|
|
swDontShowTimeout.isChecked = a.dont_show_timeout
|
2019-06-04 01:24:54 +02:00
|
|
|
swExpandCW.isChecked = a.expand_cw
|
|
|
|
swMarkSensitive.isChecked = a.default_sensitive
|
2018-01-04 19:52:25 +01:00
|
|
|
cbNotificationMention.isChecked = a.notification_mention
|
|
|
|
cbNotificationBoost.isChecked = a.notification_boost
|
|
|
|
cbNotificationFavourite.isChecked = a.notification_favourite
|
|
|
|
cbNotificationFollow.isChecked = a.notification_follow
|
2018-08-30 08:51:32 +02:00
|
|
|
cbNotificationReaction.isChecked = a.notification_reaction
|
|
|
|
cbNotificationVote.isChecked = a.notification_vote
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
cbConfirmFollow.isChecked = a.confirm_follow
|
|
|
|
cbConfirmFollowLockedUser.isChecked = a.confirm_follow_locked
|
|
|
|
cbConfirmUnfollow.isChecked = a.confirm_unfollow
|
|
|
|
cbConfirmBoost.isChecked = a.confirm_boost
|
2018-04-17 14:41:22 +02:00
|
|
|
cbConfirmFavourite.isChecked = a.confirm_favourite
|
2018-04-20 12:43:09 +02:00
|
|
|
cbConfirmUnboost.isChecked = a.confirm_unboost
|
|
|
|
cbConfirmUnfavourite.isChecked = a.confirm_unfavourite
|
2018-05-04 15:35:01 +02:00
|
|
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
cbConfirmToot.isChecked = a.confirm_post
|
|
|
|
|
|
|
|
notification_sound_uri = a.sound_uri
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
etDefaultText.setText(a.default_text)
|
2019-08-12 05:32:39 +02:00
|
|
|
etMaxTootChars.setText(a.max_toot_chars.toString())
|
2019-09-12 13:59:33 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
loading = false
|
|
|
|
|
|
|
|
val enabled = ! a.isPseudo
|
|
|
|
btnAccessToken.isEnabled = enabled
|
|
|
|
btnInputAccessToken.isEnabled = enabled
|
|
|
|
btnVisibility.isEnabled = enabled
|
2018-05-12 10:17:12 +02:00
|
|
|
btnPushSubscription.isEnabled = enabled
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
btnNotificationSoundEdit.isEnabled = Build.VERSION.SDK_INT < 26 && enabled
|
|
|
|
btnNotificationSoundReset.isEnabled = Build.VERSION.SDK_INT < 26 && enabled
|
|
|
|
btnNotificationStyleEdit.isEnabled = Build.VERSION.SDK_INT >= 26 && enabled
|
|
|
|
|
|
|
|
cbNotificationMention.isEnabled = enabled
|
|
|
|
cbNotificationBoost.isEnabled = enabled
|
|
|
|
cbNotificationFavourite.isEnabled = enabled
|
|
|
|
cbNotificationFollow.isEnabled = enabled
|
2018-08-30 08:51:32 +02:00
|
|
|
cbNotificationReaction.isEnabled = enabled
|
|
|
|
cbNotificationVote.isEnabled = enabled
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
cbConfirmFollow.isEnabled = enabled
|
|
|
|
cbConfirmFollowLockedUser.isEnabled = enabled
|
|
|
|
cbConfirmUnfollow.isEnabled = enabled
|
|
|
|
cbConfirmBoost.isEnabled = enabled
|
2018-04-17 14:41:22 +02:00
|
|
|
cbConfirmFavourite.isEnabled = enabled
|
2018-04-20 12:43:09 +02:00
|
|
|
cbConfirmUnboost.isEnabled = enabled
|
|
|
|
cbConfirmUnfavourite.isEnabled = enabled
|
2018-01-04 19:52:25 +01:00
|
|
|
cbConfirmToot.isEnabled = enabled
|
|
|
|
|
2018-03-10 01:28:53 +01:00
|
|
|
|
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
showVisibility()
|
2018-01-04 19:52:25 +01:00
|
|
|
showAcctColor()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun showAcctColor() {
|
|
|
|
val ac = AcctColor.load(full_acct)
|
2019-01-21 00:00:59 +01:00
|
|
|
tvUserCustom.backgroundColor = ac.color_bg
|
|
|
|
tvUserCustom.text = ac.nickname?.notEmpty() ?: full_acct
|
|
|
|
tvUserCustom.textColor = ac.color_fg.notZero()
|
|
|
|
?: getAttributeColor(this, R.attr.colorTimeSmall)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun saveUIToData() {
|
2018-01-10 16:47:35 +01:00
|
|
|
if(! ::account.isInitialized) return
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
if(loading) return
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
account.visibility = visibility
|
|
|
|
account.dont_hide_nsfw = swNSFWOpen.isChecked
|
|
|
|
account.dont_show_timeout = swDontShowTimeout.isChecked
|
2019-06-04 01:24:54 +02:00
|
|
|
account.expand_cw = swExpandCW.isChecked
|
|
|
|
account.default_sensitive = swMarkSensitive.isChecked
|
2018-01-10 16:47:35 +01:00
|
|
|
account.notification_mention = cbNotificationMention.isChecked
|
|
|
|
account.notification_boost = cbNotificationBoost.isChecked
|
|
|
|
account.notification_favourite = cbNotificationFavourite.isChecked
|
|
|
|
account.notification_follow = cbNotificationFollow.isChecked
|
2018-08-30 08:51:32 +02:00
|
|
|
account.notification_reaction = cbNotificationReaction.isChecked
|
|
|
|
account.notification_vote = cbNotificationVote.isChecked
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
account.sound_uri = notification_sound_uri ?: ""
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
account.confirm_follow = cbConfirmFollow.isChecked
|
|
|
|
account.confirm_follow_locked = cbConfirmFollowLockedUser.isChecked
|
|
|
|
account.confirm_unfollow = cbConfirmUnfollow.isChecked
|
|
|
|
account.confirm_boost = cbConfirmBoost.isChecked
|
2018-04-17 14:41:22 +02:00
|
|
|
account.confirm_favourite = cbConfirmFavourite.isChecked
|
2018-04-20 12:43:09 +02:00
|
|
|
account.confirm_unboost = cbConfirmUnboost.isChecked
|
|
|
|
account.confirm_unfavourite = cbConfirmUnfavourite.isChecked
|
2018-01-10 16:47:35 +01:00
|
|
|
account.confirm_post = cbConfirmToot.isChecked
|
2018-08-04 20:56:51 +02:00
|
|
|
account.default_text = etDefaultText.text.toString()
|
2019-09-12 13:59:33 +02:00
|
|
|
|
2019-08-12 05:32:39 +02:00
|
|
|
val num = etMaxTootChars.parseInt()
|
2019-09-12 13:59:33 +02:00
|
|
|
account.max_toot_chars = if(num != null && num >= 0) {
|
2019-08-12 05:32:39 +02:00
|
|
|
num
|
2019-09-12 13:59:33 +02:00
|
|
|
} else {
|
2019-08-12 05:32:39 +02:00
|
|
|
0
|
|
|
|
}
|
2019-09-12 13:59:33 +02:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
account.saveSetting()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCheckedChanged(buttonView : CompoundButton, isChecked : Boolean) {
|
2018-05-04 15:35:01 +02:00
|
|
|
if(buttonView == cbLocked) {
|
|
|
|
if(! profile_busy) sendLocked(isChecked)
|
|
|
|
} else {
|
2018-03-10 01:28:53 +01:00
|
|
|
saveUIToData()
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(v : View) {
|
|
|
|
when(v.id) {
|
|
|
|
R.id.btnAccessToken -> performAccessToken()
|
|
|
|
R.id.btnInputAccessToken -> inputAccessToken()
|
|
|
|
|
|
|
|
R.id.btnAccountRemove -> performAccountRemove()
|
2019-06-04 01:24:54 +02:00
|
|
|
R.id.btnLoadPreference -> performLoadPreference()
|
2018-01-04 19:52:25 +01:00
|
|
|
R.id.btnVisibility -> performVisibility()
|
2019-01-16 16:27:37 +01:00
|
|
|
R.id.btnOpenBrowser -> App1.openBrowser(
|
|
|
|
this@ActAccountSetting,
|
|
|
|
"https://" + account.host + "/"
|
|
|
|
)
|
2018-05-12 10:17:12 +02:00
|
|
|
R.id.btnPushSubscription -> startTest()
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
R.id.btnUserCustom -> ActNickname.open(
|
|
|
|
this,
|
|
|
|
full_acct,
|
|
|
|
false,
|
|
|
|
REQUEST_CODE_ACCT_CUSTOMIZE
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
R.id.btnNotificationSoundEdit -> openNotificationSoundPicker()
|
|
|
|
|
|
|
|
R.id.btnNotificationSoundReset -> {
|
|
|
|
notification_sound_uri = ""
|
|
|
|
saveUIToData()
|
|
|
|
}
|
|
|
|
|
|
|
|
R.id.btnProfileAvatar -> pickAvatarImage()
|
|
|
|
|
|
|
|
R.id.btnProfileHeader -> pickHeaderImage()
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
R.id.btnDisplayName -> sendDisplayName()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
R.id.btnNote -> sendNote()
|
|
|
|
|
|
|
|
R.id.btnFields -> sendFields()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
R.id.btnNotificationStyleEdit -> if(Build.VERSION.SDK_INT >= 26) {
|
2018-01-10 16:47:35 +01:00
|
|
|
val channel = NotificationHelper.createNotificationChannel(this, account)
|
2018-01-04 19:52:25 +01:00
|
|
|
val intent = Intent("android.settings.CHANNEL_NOTIFICATION_SETTINGS")
|
|
|
|
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel.id)
|
|
|
|
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
|
|
|
startActivity(intent)
|
2018-05-04 15:35:01 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
private fun showVisibility() {
|
2018-12-02 11:25:00 +01:00
|
|
|
btnVisibility.text = Styler.getVisibilityString(this, account.isMisskey, visibility)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun performVisibility() {
|
2018-08-20 19:37:42 +02:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val list = if(account.isMisskey) {
|
2018-08-20 19:37:42 +02:00
|
|
|
arrayOf(
|
2018-12-02 11:25:00 +01:00
|
|
|
// TootVisibility.WebSetting,
|
2018-08-20 19:37:42 +02:00
|
|
|
TootVisibility.Public,
|
|
|
|
TootVisibility.UnlistedHome,
|
|
|
|
TootVisibility.PrivateFollowers,
|
2018-11-16 00:43:10 +01:00
|
|
|
TootVisibility.LocalPublic,
|
|
|
|
TootVisibility.LocalHome,
|
|
|
|
TootVisibility.LocalFollowers,
|
2018-08-20 19:37:42 +02:00
|
|
|
TootVisibility.DirectSpecified,
|
|
|
|
TootVisibility.DirectPrivate
|
|
|
|
)
|
2018-12-02 11:25:00 +01:00
|
|
|
} else {
|
2018-08-20 19:37:42 +02:00
|
|
|
arrayOf(
|
|
|
|
TootVisibility.WebSetting,
|
|
|
|
TootVisibility.Public,
|
|
|
|
TootVisibility.UnlistedHome,
|
|
|
|
TootVisibility.PrivateFollowers,
|
|
|
|
TootVisibility.DirectSpecified
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val caption_list = list.map {
|
|
|
|
Styler.getVisibilityCaption(this, account.isMisskey, it)
|
2018-08-20 19:37:42 +02:00
|
|
|
}.toTypedArray()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.choose_visibility)
|
|
|
|
.setItems(caption_list) { _, which ->
|
2019-08-24 05:35:22 +02:00
|
|
|
if(which in list.indices) {
|
2018-08-20 19:37:42 +02:00
|
|
|
visibility = list[which]
|
2019-06-04 01:24:54 +02:00
|
|
|
showVisibility()
|
2018-08-20 19:37:42 +02:00
|
|
|
saveUIToData()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
.show()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
private fun performLoadPreference() {
|
|
|
|
|
|
|
|
TootTaskRunner(this).run(account, object : TootTask {
|
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
|
|
|
return client.request("/api/v1/preferences")
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
|
|
|
result ?: return
|
|
|
|
|
|
|
|
val json = result.jsonObject
|
|
|
|
if(json == null) {
|
|
|
|
showToast(this@ActAccountSetting, true, result.error)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var bChanged = false
|
|
|
|
try {
|
|
|
|
loading = true
|
2019-09-12 13:59:33 +02:00
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
val tmpVisibility =
|
|
|
|
TootVisibility.parseMastodon(json.parseString("posting:default:visibility"))
|
|
|
|
if(tmpVisibility != null) {
|
|
|
|
bChanged = true
|
|
|
|
visibility = tmpVisibility
|
|
|
|
showVisibility()
|
|
|
|
}
|
|
|
|
|
|
|
|
val tmpDefaultSensitive = json.parseBoolean("posting:default:sensitive")
|
|
|
|
if(tmpDefaultSensitive != null) {
|
|
|
|
bChanged = true
|
|
|
|
swMarkSensitive.isChecked = tmpDefaultSensitive
|
|
|
|
}
|
|
|
|
|
|
|
|
val tmpExpandMedia = json.parseString("reading:expand:media")
|
|
|
|
if(tmpExpandMedia?.isNotEmpty() == true) {
|
|
|
|
bChanged = true
|
|
|
|
swNSFWOpen.isChecked = (tmpExpandMedia == "show_all")
|
|
|
|
}
|
|
|
|
|
|
|
|
val tmpExpandCW = json.parseBoolean("reading:expand:spoilers")
|
|
|
|
if(tmpExpandCW != null) {
|
|
|
|
bChanged = true
|
|
|
|
swExpandCW.isChecked = tmpExpandCW
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
loading = false
|
|
|
|
if(bChanged) saveUIToData()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
private fun performAccountRemove() {
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.confirm)
|
|
|
|
.setMessage(R.string.confirm_account_remove)
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ ->
|
2018-01-10 16:47:35 +01:00
|
|
|
account.delete()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
val pref = Pref.pref(this@ActAccountSetting)
|
2018-01-21 13:46:36 +01:00
|
|
|
if(account.db_id == Pref.lpTabletTootDefaultAccount(pref)) {
|
2018-01-17 02:16:26 +01:00
|
|
|
pref.edit().put(Pref.lpTabletTootDefaultAccount, - 1L).apply()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
finish()
|
|
|
|
|
|
|
|
val task = @SuppressLint("StaticFieldLeak")
|
2018-01-10 16:47:35 +01:00
|
|
|
object : AsyncTask<Void, Void, String?>() {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
fun unregister() {
|
2018-01-04 19:52:25 +01:00
|
|
|
try {
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
val install_id = PrefDevice.prefDevice(this@ActAccountSetting)
|
|
|
|
.getString(PrefDevice.KEY_INSTALL_ID, null)
|
2018-01-10 16:47:35 +01:00
|
|
|
if(install_id?.isEmpty() != false) {
|
2018-01-04 19:52:25 +01:00
|
|
|
log.d("performAccountRemove: missing install_id")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
val tag = account.notification_tag
|
|
|
|
if(tag?.isEmpty() != false) {
|
2018-01-04 19:52:25 +01:00
|
|
|
log.d("performAccountRemove: missing notification_tag")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val call = App1.ok_http_client.newCall(
|
2018-01-21 17:47:13 +01:00
|
|
|
("instance_url=" + ("https://" + account.host).encodePercent()
|
|
|
|
+ "&app_id=" + packageName.encodePercent()
|
2018-12-02 11:25:00 +01:00
|
|
|
+ "&tag=" + tag
|
|
|
|
)
|
2019-08-24 05:35:22 +02:00
|
|
|
.toFormRequestBody()
|
2018-12-02 11:25:00 +01:00
|
|
|
.toPost()
|
|
|
|
.url(PollingWorker.APP_SERVER + "/unregister")
|
|
|
|
.build()
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
val response = call.execute()
|
|
|
|
|
|
|
|
log.e("performAccountRemove: %s", response)
|
|
|
|
|
|
|
|
} catch(ex : Throwable) {
|
2018-12-02 11:25:00 +01:00
|
|
|
log.trace(ex, "performAccountRemove failed.")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun doInBackground(vararg params : Void) : String? {
|
|
|
|
unregister()
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
override fun onCancelled(s : String?) {
|
2018-01-04 19:52:25 +01:00
|
|
|
onPostExecute(s)
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
override fun onPostExecute(s : String?) {
|
|
|
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
task.executeOnExecutor(App1.task_executor)
|
|
|
|
}
|
|
|
|
.show()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
private fun performAccessToken() {
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
TootTaskRunner(this@ActAccountSetting).run(account, object : TootTask {
|
2018-01-04 19:52:25 +01:00
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
2019-03-13 18:34:56 +01:00
|
|
|
return client.authentication1(
|
|
|
|
Pref.spClientName(this@ActAccountSetting),
|
|
|
|
forceUpdateClient = false
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
|
|
|
result ?: return // cancelled.
|
|
|
|
|
2018-11-30 05:42:20 +01:00
|
|
|
val uri = result.string.mayUri()
|
2018-01-04 19:52:25 +01:00
|
|
|
val error = result.error
|
2018-12-02 11:25:00 +01:00
|
|
|
when {
|
|
|
|
uri != null -> {
|
2018-01-04 19:52:25 +01:00
|
|
|
val data = Intent()
|
2018-11-30 05:42:20 +01:00
|
|
|
data.data = uri
|
2018-01-04 19:52:25 +01:00
|
|
|
setResult(Activity.RESULT_OK, data)
|
|
|
|
finish()
|
|
|
|
}
|
2018-12-02 11:25:00 +01:00
|
|
|
|
|
|
|
error != null -> {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this@ActAccountSetting, true, error)
|
2018-01-04 19:52:25 +01:00
|
|
|
log.e("can't get oauth browser URL. $error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun inputAccessToken() {
|
|
|
|
|
|
|
|
val data = Intent()
|
2018-01-10 16:47:35 +01:00
|
|
|
data.putExtra(EXTRA_DB_ID, account.db_id)
|
2018-01-04 19:52:25 +01:00
|
|
|
setResult(RESULT_INPUT_ACCESS_TOKEN, data)
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun openNotificationSoundPicker() {
|
|
|
|
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, R.string.notification_sound)
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false)
|
2018-11-30 05:42:20 +01:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
notification_sound_uri.mayUri()?.let { uri ->
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
val chooser = Intent.createChooser(intent, getString(R.string.notification_sound))
|
|
|
|
startActivityForResult(chooser, REQUEST_CODE_NOTIFICATION_SOUND)
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
private fun initializeProfile() {
|
|
|
|
// 初期状態
|
2019-01-16 13:33:07 +01:00
|
|
|
val question_id = R.drawable.wide_question
|
2019-01-16 16:27:37 +01:00
|
|
|
ivProfileAvatar.setErrorImage(defaultColorIcon(this, question_id))
|
|
|
|
ivProfileAvatar.setDefaultImage(defaultColorIcon(this, question_id))
|
2018-05-04 15:35:01 +02:00
|
|
|
|
|
|
|
val loadingText = when(account.isPseudo) {
|
|
|
|
true -> "(disabled for pseudo account)"
|
|
|
|
else -> "(loading…)"
|
|
|
|
}
|
|
|
|
etDisplayName.setText(loadingText)
|
|
|
|
etNote.setText(loadingText)
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
// 初期状態では編集不可能
|
|
|
|
btnProfileAvatar.isEnabled = false
|
|
|
|
btnProfileHeader.isEnabled = false
|
|
|
|
etDisplayName.isEnabled = false
|
|
|
|
btnDisplayName.isEnabled = false
|
|
|
|
etNote.isEnabled = false
|
|
|
|
btnNote.isEnabled = false
|
2018-03-10 01:28:53 +01:00
|
|
|
cbLocked.isEnabled = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
for(et in listEtFieldName) {
|
|
|
|
et.setText(loadingText)
|
|
|
|
et.isEnabled = false
|
|
|
|
}
|
|
|
|
for(et in listEtFieldValue) {
|
|
|
|
et.setText(loadingText)
|
|
|
|
et.isEnabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 疑似アカウントなら編集不可のまま
|
|
|
|
if(! account.isPseudo) loadProfile()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun loadProfile() {
|
|
|
|
// サーバから情報をロードする
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
TootTaskRunner(this).run(account, object : TootTask {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
var data : TootAccount? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
2018-12-02 11:25:00 +01:00
|
|
|
if(account.isMisskey) {
|
2018-08-20 19:37:42 +02:00
|
|
|
val params = account.putMisskeyApiToken(JSONObject())
|
2018-12-02 11:25:00 +01:00
|
|
|
val result = client.request("/api/i", params.toPostRequestBuilder())
|
2018-08-20 19:37:42 +02:00
|
|
|
val jsonObject = result?.jsonObject
|
|
|
|
if(jsonObject != null) {
|
|
|
|
data = TootParser(this@ActAccountSetting, account).account(jsonObject)
|
|
|
|
if(data == null) return TootApiResult("TootAccount parse failed.")
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
} else {
|
2018-12-25 12:54:41 +01:00
|
|
|
|
2019-01-16 16:27:37 +01:00
|
|
|
var result = account.checkConfirmed(this@ActAccountSetting, client)
|
|
|
|
if(result == null || result.error != null) return result
|
2018-12-25 12:54:41 +01:00
|
|
|
|
|
|
|
result = client.request("/api/v1/accounts/verify_credentials")
|
2018-08-20 19:37:42 +02:00
|
|
|
val jsonObject = result?.jsonObject
|
|
|
|
if(jsonObject != null) {
|
|
|
|
data = TootParser(this@ActAccountSetting, account).account(jsonObject)
|
|
|
|
if(data == null) return TootApiResult("TootAccount parse failed.")
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
|
|
|
if(result == null) return // cancelled.
|
|
|
|
|
|
|
|
val data = this.data
|
|
|
|
if(data != null) {
|
|
|
|
showProfile(data)
|
|
|
|
} else {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this@ActAccountSetting, true, result.error)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
var profile_busy : Boolean = false
|
2018-03-10 01:28:53 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
internal fun showProfile(src : TootAccount) {
|
2018-03-10 01:28:53 +01:00
|
|
|
profile_busy = true
|
|
|
|
try {
|
|
|
|
ivProfileAvatar.setImageUrl(
|
|
|
|
App1.pref,
|
|
|
|
Styler.calcIconRound(ivProfileAvatar.layoutParams),
|
|
|
|
src.avatar_static,
|
|
|
|
src.avatar
|
|
|
|
)
|
|
|
|
|
|
|
|
ivProfileHeader.setImageUrl(
|
|
|
|
App1.pref,
|
|
|
|
0f,
|
|
|
|
src.header_static,
|
|
|
|
src.header
|
|
|
|
)
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
val decodeOptions = DecodeOptions(
|
|
|
|
context = this@ActAccountSetting,
|
2018-05-06 13:08:06 +02:00
|
|
|
linkHelper = account,
|
2018-05-04 15:35:01 +02:00
|
|
|
emojiMapProfile = src.profile_emojis,
|
2018-05-06 13:08:06 +02:00
|
|
|
emojiMapCustom = src.custom_emojis
|
2018-05-04 15:35:01 +02:00
|
|
|
)
|
|
|
|
|
2018-03-10 01:28:53 +01:00
|
|
|
val display_name = src.display_name
|
2018-05-04 15:35:01 +02:00
|
|
|
val name = decodeOptions.decodeEmoji(display_name)
|
2018-03-10 01:28:53 +01:00
|
|
|
etDisplayName.setText(name)
|
|
|
|
name_invalidator.register(name)
|
|
|
|
|
|
|
|
val noteString = src.source?.note ?: src.note
|
2018-09-05 16:03:26 +02:00
|
|
|
val noteSpannable = when {
|
|
|
|
account.isMisskey -> {
|
2018-09-07 13:46:43 +02:00
|
|
|
SpannableString(noteString ?: "")
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
2018-12-02 11:25:00 +01:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
else -> {
|
|
|
|
decodeOptions.decodeEmoji(noteString)
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 01:28:53 +01:00
|
|
|
|
|
|
|
etNote.setText(noteSpannable)
|
|
|
|
note_invalidator.register(noteSpannable)
|
|
|
|
|
|
|
|
cbLocked.isChecked = src.locked
|
|
|
|
|
|
|
|
// 編集可能にする
|
|
|
|
btnProfileAvatar.isEnabled = true
|
|
|
|
btnProfileHeader.isEnabled = true
|
|
|
|
etDisplayName.isEnabled = true
|
|
|
|
btnDisplayName.isEnabled = true
|
|
|
|
etNote.isEnabled = true
|
|
|
|
btnNote.isEnabled = true
|
|
|
|
cbLocked.isEnabled = true
|
2018-05-04 15:35:01 +02:00
|
|
|
|
|
|
|
if(src.source?.fields != null) {
|
|
|
|
val fields = src.source.fields
|
|
|
|
listEtFieldName.forEachIndexed { i, et ->
|
2019-09-12 13:59:33 +02:00
|
|
|
// いつからかfields name にもカスタム絵文字が使えるようになった
|
|
|
|
// https://github.com/tootsuite/mastodon/pull/11350
|
|
|
|
// しかし
|
|
|
|
val text = decodeOptions.decodeEmoji(
|
2018-05-06 13:08:06 +02:00
|
|
|
when {
|
|
|
|
i >= fields.size -> ""
|
2018-10-09 08:39:05 +02:00
|
|
|
else -> fields[i].name
|
2018-05-06 13:08:06 +02:00
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
)
|
2018-05-12 10:17:12 +02:00
|
|
|
et.setText(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
et.isEnabled = true
|
2018-05-12 10:17:12 +02:00
|
|
|
val invalidator = NetworkEmojiInvalidator(et.handler, et)
|
2018-05-06 13:08:06 +02:00
|
|
|
invalidator.register(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
listEtFieldValue.forEachIndexed { i, et ->
|
2018-05-12 10:17:12 +02:00
|
|
|
val text = decodeOptions.decodeEmoji(
|
2018-05-06 13:08:06 +02:00
|
|
|
when {
|
|
|
|
i >= fields.size -> ""
|
2018-10-09 08:39:05 +02:00
|
|
|
else -> fields[i].value
|
2018-05-06 13:08:06 +02:00
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
)
|
2018-05-12 10:17:12 +02:00
|
|
|
et.setText(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
et.isEnabled = true
|
2018-05-12 10:17:12 +02:00
|
|
|
val invalidator = NetworkEmojiInvalidator(et.handler, et)
|
2018-05-06 13:08:06 +02:00
|
|
|
invalidator.register(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
val fields = src.fields
|
|
|
|
|
|
|
|
listEtFieldName.forEachIndexed { i, et ->
|
2019-09-12 13:59:33 +02:00
|
|
|
// いつからかfields name にもカスタム絵文字が使えるようになった
|
|
|
|
// https://github.com/tootsuite/mastodon/pull/11350
|
|
|
|
val text = decodeOptions.decodeEmoji(
|
2018-05-06 13:08:06 +02:00
|
|
|
when {
|
|
|
|
fields == null || i >= fields.size -> ""
|
2018-10-09 08:39:05 +02:00
|
|
|
else -> fields[i].name
|
2018-05-06 13:08:06 +02:00
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
)
|
2018-05-06 13:08:06 +02:00
|
|
|
et.setText(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
et.isEnabled = true
|
2018-05-12 10:17:12 +02:00
|
|
|
val invalidator = NetworkEmojiInvalidator(et.handler, et)
|
2018-05-06 13:08:06 +02:00
|
|
|
invalidator.register(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
listEtFieldValue.forEachIndexed { i, et ->
|
2018-05-12 10:17:12 +02:00
|
|
|
val text = decodeOptions.decodeHTML(
|
2018-05-04 15:35:01 +02:00
|
|
|
when {
|
|
|
|
fields == null || i >= fields.size -> ""
|
2018-10-09 08:39:05 +02:00
|
|
|
else -> fields[i].value
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
|
|
|
)
|
2018-05-06 13:08:06 +02:00
|
|
|
et.text = text
|
2018-05-04 15:35:01 +02:00
|
|
|
et.isEnabled = true
|
2018-05-12 10:17:12 +02:00
|
|
|
val invalidator = NetworkEmojiInvalidator(et.handler, et)
|
2018-05-06 13:08:06 +02:00
|
|
|
invalidator.register(text)
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
2018-03-10 01:28:53 +01:00
|
|
|
profile_busy = false
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-11 15:42:54 +02:00
|
|
|
private fun updateCredential(key : String, value : Any) {
|
2018-05-04 15:35:01 +02:00
|
|
|
updateCredential(listOf(Pair(key, value)))
|
|
|
|
}
|
|
|
|
|
2018-05-11 15:42:54 +02:00
|
|
|
private fun updateCredential(args : List<Pair<String, Any>>) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
TootTaskRunner(this).run(account, object : TootTask {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
private fun uploadImageMisskey(
|
|
|
|
client : TootApiClient,
|
|
|
|
opener : InputStreamOpener
|
2019-01-16 16:27:37 +01:00
|
|
|
) : Pair<TootApiResult?, TootAttachment?> {
|
2018-09-05 16:03:26 +02:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val size = getStreamSize(true, opener.open())
|
2018-09-05 16:03:26 +02:00
|
|
|
|
|
|
|
val multipart_builder = MultipartBody.Builder()
|
|
|
|
.setType(MultipartBody.FORM)
|
|
|
|
|
|
|
|
val apiKey =
|
|
|
|
account.token_info?.parseString(TootApiClient.KEY_API_KEY_MISSKEY)
|
|
|
|
if(apiKey?.isNotEmpty() == true) {
|
|
|
|
multipart_builder.addFormDataPart("i", apiKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
multipart_builder.addFormDataPart(
|
|
|
|
"file",
|
2018-12-02 11:25:00 +01:00
|
|
|
getDocumentName(contentResolver, opener.uri),
|
2018-09-05 16:03:26 +02:00
|
|
|
object : RequestBody() {
|
|
|
|
override fun contentType() : MediaType? {
|
2019-08-24 05:35:22 +02:00
|
|
|
return opener.mimeType.toMediaType()
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
override fun contentLength() : Long {
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
override fun writeTo(sink : BufferedSink) {
|
|
|
|
opener.open().use { inData ->
|
|
|
|
val tmp = ByteArray(4096)
|
|
|
|
while(true) {
|
|
|
|
val r = inData.read(tmp, 0, tmp.size)
|
|
|
|
if(r <= 0) break
|
|
|
|
sink.write(tmp, 0, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-01-16 16:27:37 +01:00
|
|
|
var ta : TootAttachment? = null
|
2018-12-02 11:25:00 +01:00
|
|
|
val result = client.request(
|
|
|
|
"/api/drive/files/create",
|
|
|
|
multipart_builder.build().toPost()
|
2019-01-16 16:27:37 +01:00
|
|
|
)?.also { result ->
|
|
|
|
val jsonObject = result.jsonObject
|
|
|
|
if(jsonObject != null) {
|
|
|
|
ta = parseItem(::TootAttachment, ServiceType.MISSKEY, jsonObject)
|
|
|
|
if(ta == null) result.error = "TootAttachment.parse failed"
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-16 16:27:37 +01:00
|
|
|
|
|
|
|
return Pair(result, ta)
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
var data : TootAccount? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
try {
|
2018-12-02 11:25:00 +01:00
|
|
|
if(account.isMisskey) {
|
2018-09-05 16:03:26 +02:00
|
|
|
val params = account.putMisskeyApiToken()
|
2018-02-12 14:56:37 +01:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
for(arg in args) {
|
|
|
|
val key = arg.first
|
|
|
|
val value = arg.second
|
2018-05-04 15:35:01 +02:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val misskeyKey = when(key) {
|
|
|
|
"header" -> "bannerId"
|
|
|
|
"avatar" -> "avatarId"
|
|
|
|
"display_name" -> "name"
|
2018-09-05 16:03:26 +02:00
|
|
|
"note" -> "description"
|
|
|
|
"locked" -> "isLocked"
|
2018-12-02 11:25:00 +01:00
|
|
|
else -> return TootApiResult("Misskey does not support property '${key}'")
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
when(value) {
|
2018-12-02 11:25:00 +01:00
|
|
|
is String -> params.put(misskeyKey, value)
|
2018-09-05 16:03:26 +02:00
|
|
|
is Boolean -> params.put(misskeyKey, value)
|
2018-12-02 11:25:00 +01:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
is InputStreamOpener -> {
|
2019-01-16 16:27:37 +01:00
|
|
|
val (result, ta) = uploadImageMisskey(client, value)
|
|
|
|
ta ?: return result
|
2018-09-05 16:03:26 +02:00
|
|
|
params.put(misskeyKey, ta.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val result =
|
2018-12-02 11:25:00 +01:00
|
|
|
client.request("/api/i/update", params.toPostRequestBuilder())
|
2018-09-05 16:03:26 +02:00
|
|
|
val jsonObject = result?.jsonObject
|
|
|
|
if(jsonObject != null) {
|
|
|
|
val a = TootParser(this@ActAccountSetting, account).account(jsonObject)
|
|
|
|
?: return TootApiResult("TootAccount parse failed.")
|
|
|
|
data = a
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
} else {
|
2018-09-05 16:03:26 +02:00
|
|
|
val multipart_body_builder = MultipartBody.Builder()
|
|
|
|
.setType(MultipartBody.FORM)
|
|
|
|
|
|
|
|
for(arg in args) {
|
|
|
|
val key = arg.first
|
|
|
|
val value = arg.second
|
2018-05-04 15:35:01 +02:00
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
if(value is String) {
|
|
|
|
multipart_body_builder.addFormDataPart(key, value)
|
|
|
|
} else if(value is Boolean) {
|
|
|
|
multipart_body_builder.addFormDataPart(
|
|
|
|
key,
|
|
|
|
if(value) "true" else "false"
|
|
|
|
)
|
|
|
|
|
|
|
|
} else if(value is InputStreamOpener) {
|
|
|
|
|
|
|
|
val fileName = "%x".format(System.currentTimeMillis())
|
|
|
|
|
|
|
|
multipart_body_builder.addFormDataPart(
|
|
|
|
key,
|
|
|
|
fileName,
|
|
|
|
object : RequestBody() {
|
|
|
|
override fun contentType() : MediaType? {
|
2019-08-24 05:35:22 +02:00
|
|
|
return value.mimeType.toMediaType()
|
2018-09-05 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun writeTo(sink : BufferedSink) {
|
|
|
|
value.open().use { inData ->
|
|
|
|
val tmp = ByteArray(4096)
|
|
|
|
while(true) {
|
|
|
|
val r = inData.read(tmp, 0, tmp.size)
|
|
|
|
if(r <= 0) break
|
|
|
|
sink.write(tmp, 0, r)
|
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
2018-02-12 14:56:37 +01:00
|
|
|
}
|
2018-09-05 16:03:26 +02:00
|
|
|
})
|
|
|
|
}
|
2018-05-04 15:35:01 +02:00
|
|
|
}
|
2018-09-05 16:03:26 +02:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val result = client.request(
|
|
|
|
"/api/v1/accounts/update_credentials",
|
|
|
|
multipart_body_builder.build().toPatch()
|
|
|
|
)
|
2018-09-05 16:03:26 +02:00
|
|
|
val jsonObject = result?.jsonObject
|
|
|
|
if(jsonObject != null) {
|
|
|
|
val a = TootParser(this@ActAccountSetting, account).account(jsonObject)
|
|
|
|
?: return TootApiResult("TootAccount parse failed.")
|
|
|
|
data = a
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
2018-05-04 15:35:01 +02:00
|
|
|
for(arg in args) {
|
|
|
|
val value = arg.second
|
|
|
|
(value as? InputStreamOpener)?.deleteTempFile()
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
|
|
|
if(result == null) return // cancelled.
|
|
|
|
|
|
|
|
val data = this.data
|
|
|
|
if(data != null) {
|
|
|
|
showProfile(data)
|
|
|
|
} else {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this@ActAccountSetting, true, result.error)
|
2018-05-04 15:35:01 +02:00
|
|
|
for(arg in args) {
|
|
|
|
val key = arg.first
|
|
|
|
val value = arg.second
|
|
|
|
if(key == "locked" && value is Boolean) {
|
|
|
|
profile_busy = true
|
|
|
|
cbLocked.isChecked = ! value
|
|
|
|
profile_busy = false
|
|
|
|
}
|
2018-03-10 01:28:53 +01:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
private fun sendDisplayName(bConfirmed : Boolean = false) {
|
2018-01-04 19:52:25 +01:00
|
|
|
val sv = etDisplayName.text.toString()
|
|
|
|
if(! bConfirmed) {
|
|
|
|
val length = sv.codePointCount(0, sv.length)
|
|
|
|
if(length > max_length_display_name) {
|
|
|
|
AlertDialog.Builder(this)
|
2018-01-21 13:46:36 +01:00
|
|
|
.setMessage(
|
|
|
|
getString(
|
|
|
|
R.string.length_warning,
|
|
|
|
getString(R.string.display_name),
|
|
|
|
length,
|
|
|
|
max_length_display_name
|
|
|
|
)
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
.setNegativeButton(R.string.cancel, null)
|
2018-05-04 15:35:01 +02:00
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> sendDisplayName(bConfirmed = true) }
|
2018-01-04 19:52:25 +01:00
|
|
|
.setCancelable(true)
|
|
|
|
.show()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 14:56:37 +01:00
|
|
|
updateCredential("display_name", EmojiDecoder.decodeShortCode(sv))
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
private fun sendNote(bConfirmed : Boolean = false) {
|
2018-01-04 19:52:25 +01:00
|
|
|
val sv = etNote.text.toString()
|
|
|
|
if(! bConfirmed) {
|
2019-01-06 09:20:37 +01:00
|
|
|
|
2019-01-18 19:05:14 +01:00
|
|
|
val length = TootStatus.countText(sv)
|
2018-01-04 19:52:25 +01:00
|
|
|
if(length > max_length_note) {
|
|
|
|
AlertDialog.Builder(this)
|
2018-01-21 13:46:36 +01:00
|
|
|
.setMessage(
|
|
|
|
getString(
|
|
|
|
R.string.length_warning,
|
|
|
|
getString(R.string.note),
|
|
|
|
length,
|
|
|
|
max_length_note
|
|
|
|
)
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
.setNegativeButton(R.string.cancel, null)
|
2018-05-04 15:35:01 +02:00
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> sendNote(bConfirmed = true) }
|
2018-01-04 19:52:25 +01:00
|
|
|
.setCancelable(true)
|
|
|
|
.show()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 14:56:37 +01:00
|
|
|
updateCredential("note", EmojiDecoder.decodeShortCode(sv))
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
private fun sendLocked(willLocked : Boolean) {
|
2018-03-10 01:28:53 +01:00
|
|
|
updateCredential("locked", willLocked)
|
|
|
|
}
|
|
|
|
|
2018-05-04 15:35:01 +02:00
|
|
|
private fun sendFields(bConfirmed : Boolean = false) {
|
|
|
|
val args = ArrayList<Pair<String, String>>()
|
|
|
|
var lengthLongest = - 1
|
2019-08-24 05:35:22 +02:00
|
|
|
for(i in listEtFieldName.indices) {
|
2018-05-04 15:35:01 +02:00
|
|
|
val k = listEtFieldName[i].text.toString().trim()
|
|
|
|
val v = listEtFieldValue[i].text.toString().trim()
|
|
|
|
args.add(Pair("fields_attributes[$i][name]", k))
|
|
|
|
args.add(Pair("fields_attributes[$i][value]", v))
|
|
|
|
|
2019-08-24 05:35:22 +02:00
|
|
|
lengthLongest = max(
|
2018-05-04 15:35:01 +02:00
|
|
|
lengthLongest,
|
2019-08-24 05:35:22 +02:00
|
|
|
max(
|
2018-05-04 15:35:01 +02:00
|
|
|
k.codePointCount(0, k.length),
|
|
|
|
v.codePointCount(0, v.length)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if(! bConfirmed && lengthLongest > max_length_fields) {
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
.setMessage(
|
|
|
|
getString(
|
|
|
|
R.string.length_warning,
|
|
|
|
getString(R.string.profile_metadata),
|
|
|
|
lengthLongest,
|
|
|
|
max_length_fields
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> sendFields(bConfirmed = true) }
|
|
|
|
.setCancelable(true)
|
|
|
|
.show()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCredential(args)
|
|
|
|
}
|
2018-03-10 01:28:53 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private fun pickAvatarImage() {
|
|
|
|
openPicker(PERMISSION_REQUEST_AVATAR)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun pickHeaderImage() {
|
|
|
|
openPicker(PERMISSION_REQUEST_HEADER)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun openPicker(permission_request_code : Int) {
|
2018-01-21 13:46:36 +01:00
|
|
|
val permissionCheck = ContextCompat.checkSelfPermission(
|
|
|
|
this,
|
2019-08-12 05:32:39 +02:00
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
2018-01-21 13:46:36 +01:00
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
preparePermission(permission_request_code)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
val a = ActionsDialog()
|
2018-09-01 16:31:06 +02:00
|
|
|
a.addAction(getString(R.string.pick_image)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
performAttachment(
|
|
|
|
if(permission_request_code == PERMISSION_REQUEST_AVATAR)
|
|
|
|
REQUEST_CODE_AVATAR_ATTACHMENT
|
|
|
|
else
|
|
|
|
REQUEST_CODE_HEADER_ATTACHMENT
|
|
|
|
)
|
|
|
|
}
|
|
|
|
a.addAction(getString(R.string.image_capture)) {
|
|
|
|
performCamera(
|
|
|
|
if(permission_request_code == PERMISSION_REQUEST_AVATAR)
|
|
|
|
REQUEST_CODE_AVATAR_CAMERA
|
|
|
|
else
|
|
|
|
REQUEST_CODE_HEADER_CAMERA
|
|
|
|
)
|
|
|
|
}
|
|
|
|
a.show(this, null)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun preparePermission(request_code : Int) {
|
|
|
|
if(Build.VERSION.SDK_INT >= 23) {
|
|
|
|
// No explanation needed, we can request the permission.
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), request_code
|
2018-01-04 19:52:25 +01:00
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, true, R.string.missing_permission_to_access_media)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onRequestPermissionsResult(
|
|
|
|
requestCode : Int, permissions : Array<String>, grantResults : IntArray
|
|
|
|
) {
|
|
|
|
when(requestCode) {
|
|
|
|
PERMISSION_REQUEST_AVATAR, PERMISSION_REQUEST_HEADER ->
|
|
|
|
// If request is cancelled, the result arrays are empty.
|
|
|
|
if(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
openPicker(requestCode)
|
|
|
|
} else {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, true, R.string.missing_permission_to_access_media)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun performAttachment(request_code : Int) {
|
|
|
|
try {
|
2019-06-20 02:22:42 +02:00
|
|
|
val intent = intentGetContent(false, getString(R.string.pick_image), arrayOf("image/*"))
|
2018-01-04 19:52:25 +01:00
|
|
|
startActivityForResult(intent, request_code)
|
|
|
|
} catch(ex : Throwable) {
|
2018-12-02 11:25:00 +01:00
|
|
|
log.trace(ex, "performAttachment failed.")
|
2018-09-07 07:51:59 +02:00
|
|
|
showToast(this, ex, "performAttachment failed.")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun performCamera(request_code : Int) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
// カメラで撮影
|
|
|
|
val filename = System.currentTimeMillis().toString() + ".jpg"
|
|
|
|
val values = ContentValues()
|
|
|
|
values.put(MediaStore.Images.Media.TITLE, filename)
|
|
|
|
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
|
2018-01-21 13:46:36 +01:00
|
|
|
uriCameraImage =
|
|
|
|
contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriCameraImage)
|
|
|
|
|
|
|
|
startActivityForResult(intent, request_code)
|
|
|
|
} catch(ex : Throwable) {
|
2018-12-02 11:25:00 +01:00
|
|
|
log.trace(ex, "opening camera app failed.")
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, ex, "opening camera app failed.")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal interface InputStreamOpener {
|
|
|
|
|
|
|
|
val mimeType : String
|
2018-02-12 14:56:37 +01:00
|
|
|
|
2018-12-02 11:25:00 +01:00
|
|
|
val uri : Uri
|
2018-09-05 16:03:26 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
@Throws(IOException::class)
|
|
|
|
fun open() : InputStream
|
|
|
|
|
|
|
|
fun deleteTempFile()
|
|
|
|
}
|
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
private fun createOpener(uriArg : Uri, mime_type : String) : InputStreamOpener {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
while(true) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 画像の種別
|
|
|
|
val is_jpeg = MIME_TYPE_JPEG == mime_type
|
|
|
|
val is_png = MIME_TYPE_PNG == mime_type
|
|
|
|
if(! is_jpeg && ! is_png) {
|
|
|
|
log.d("createOpener: source is not jpeg or png")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// 設定からリサイズ指定を読む
|
|
|
|
val resize_to = 1280
|
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
val bitmap = createResizedBitmap(this, uriArg, resize_to)
|
2018-01-04 19:52:25 +01:00
|
|
|
if(bitmap != null) {
|
|
|
|
try {
|
|
|
|
val cache_dir = externalCacheDir
|
|
|
|
if(cache_dir == null) {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, false, "getExternalCacheDir returns null.")
|
2018-01-04 19:52:25 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_dir.mkdir()
|
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
val temp_file = File(
|
|
|
|
cache_dir,
|
|
|
|
"tmp." + System.currentTimeMillis() + "." + Thread.currentThread().id
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
FileOutputStream(temp_file).use { os ->
|
|
|
|
if(is_jpeg) {
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 95, os)
|
|
|
|
} else {
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, os)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return object : InputStreamOpener {
|
|
|
|
|
|
|
|
override val mimeType : String
|
|
|
|
get() = mime_type
|
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
override val uri : Uri
|
|
|
|
get() = uriArg
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
@Throws(IOException::class)
|
2018-05-04 15:35:01 +02:00
|
|
|
override fun open() = FileInputStream(temp_file)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
override fun deleteTempFile() {
|
|
|
|
temp_file.delete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
bitmap.recycle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(ex : Throwable) {
|
2018-12-02 11:25:00 +01:00
|
|
|
log.trace(ex, "Resizing image failed.")
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, ex, "Resizing image failed.")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
2018-09-05 16:03:26 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
return object : InputStreamOpener {
|
|
|
|
|
|
|
|
override val mimeType : String
|
|
|
|
get() = mime_type
|
|
|
|
|
2018-09-05 16:03:26 +02:00
|
|
|
override val uri : Uri
|
|
|
|
get() = uriArg
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
@Throws(IOException::class)
|
|
|
|
override fun open() : InputStream {
|
2018-09-27 16:21:37 +02:00
|
|
|
return contentResolver.openInputStream(uri) ?: error("openInputStream returns null")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun deleteTempFile() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun addAttachment(request_code : Int, uri : Uri, mime_type : String?) {
|
|
|
|
|
|
|
|
if(mime_type == null) {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, false, "mime type is not provided.")
|
2018-01-04 19:52:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(! mime_type.startsWith("image/")) {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this, false, "mime type is not image.")
|
2018-01-04 19:52:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
val progress = ProgressDialogEx(this)
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
val task = @SuppressLint("StaticFieldLeak")
|
2018-02-12 14:56:37 +01:00
|
|
|
object : AsyncTask<Void, Void, InputStreamOpener?>() {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
override fun doInBackground(vararg params : Void) : InputStreamOpener? {
|
|
|
|
return try {
|
|
|
|
createOpener(uri, mime_type)
|
2018-01-04 19:52:25 +01:00
|
|
|
} catch(ex : Throwable) {
|
2018-01-21 13:46:36 +01:00
|
|
|
showToast(this@ActAccountSetting, ex, "image converting failed.")
|
2018-02-12 14:56:37 +01:00
|
|
|
null
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 14:56:37 +01:00
|
|
|
override fun onPostExecute(opener : InputStreamOpener?) {
|
2019-01-19 03:36:40 +01:00
|
|
|
progress.dismissSafe()
|
2018-02-12 14:56:37 +01:00
|
|
|
if(opener != null) {
|
|
|
|
updateCredential(
|
|
|
|
when(request_code) {
|
|
|
|
REQUEST_CODE_HEADER_ATTACHMENT, REQUEST_CODE_HEADER_CAMERA -> "header"
|
|
|
|
else -> "avatar"
|
|
|
|
},
|
|
|
|
opener
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-02-12 14:56:37 +01:00
|
|
|
|
2019-09-12 13:59:33 +02:00
|
|
|
@Suppress("DEPRECATION")
|
2018-02-12 14:56:37 +01:00
|
|
|
progress.isIndeterminate = true
|
2019-09-12 13:59:33 +02:00
|
|
|
|
|
|
|
@Suppress("DEPRECATION")
|
2018-02-12 14:56:37 +01:00
|
|
|
progress.setMessage("preparing image…")
|
2019-09-12 13:59:33 +02:00
|
|
|
|
|
|
|
progress.setOnCancelListener { task.cancel(true) }
|
2018-02-12 14:56:37 +01:00
|
|
|
progress.show()
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
task.executeOnExecutor(App1.task_executor)
|
|
|
|
}
|
|
|
|
|
2018-05-11 15:42:54 +02:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
private fun startTest() {
|
2018-05-12 10:17:12 +02:00
|
|
|
TootTaskRunner(this).run(account, object : TootTask {
|
2018-05-16 21:09:07 +02:00
|
|
|
val wps = PushSubscriptionHelper(
|
2018-05-13 13:35:17 +02:00
|
|
|
this@ActAccountSetting,
|
|
|
|
account,
|
|
|
|
verbose = true
|
|
|
|
)
|
2018-12-02 11:25:00 +01:00
|
|
|
|
2018-05-12 10:17:12 +02:00
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
2018-05-13 13:35:17 +02:00
|
|
|
return wps.updateSubscription(client)
|
2018-05-11 15:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
2018-05-12 10:17:12 +02:00
|
|
|
result ?: return
|
|
|
|
val log = wps.log
|
2018-12-02 11:25:00 +01:00
|
|
|
if(log.isNotEmpty()) {
|
2018-05-12 10:17:12 +02:00
|
|
|
AlertDialog.Builder(this@ActAccountSetting)
|
|
|
|
.setMessage(log)
|
|
|
|
.setPositiveButton(R.string.close, null)
|
|
|
|
.show()
|
|
|
|
}
|
2018-05-11 15:42:54 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-05-12 10:17:12 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|