リファクタ
This commit is contained in:
parent
34118e78a6
commit
1f92d3cdef
|
@ -1444,7 +1444,7 @@ class ActAccountSetting
|
|||
}
|
||||
|
||||
override fun onPostExecute(opener : InputStreamOpener?) {
|
||||
progress.dismiss()
|
||||
progress.dismissSafe()
|
||||
if(opener != null) {
|
||||
updateCredential(
|
||||
when(request_code) {
|
||||
|
|
|
@ -230,7 +230,7 @@ class ActAppSetting : AppCompatActivity() {
|
|||
}
|
||||
|
||||
override fun onPostExecute(result : File?) {
|
||||
progress.dismiss()
|
||||
progress.dismissSafe()
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
// cancelled.
|
||||
|
|
|
@ -242,12 +242,7 @@ class ActHighlightWordList : AppCompatActivity(), View.OnClickListener {
|
|||
}
|
||||
edit(item)
|
||||
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
|
||||
}
|
||||
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2052,18 +2052,8 @@ class ActMain : AppCompatActivity()
|
|||
override fun handleResult(result : TootApiResult?) {
|
||||
|
||||
if(afterAccountVerify(result, ta, sa, host)) {
|
||||
try {
|
||||
dialog_host?.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
|
||||
try {
|
||||
dialog_token?.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
|
||||
dialog_host?.dismissSafe()
|
||||
dialog_token?.dismissSafe()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -2750,7 +2740,7 @@ class ActMain : AppCompatActivity()
|
|||
|
||||
override fun onPostExecute(result : ArrayList<Column>?) {
|
||||
|
||||
progress.dismiss()
|
||||
progress.dismissSafe()
|
||||
|
||||
try {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
|
|
@ -1500,10 +1500,7 @@ class ActPost : AppCompatActivity(),
|
|||
pa.attachment = new_attachment
|
||||
showMediaAttachment()
|
||||
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
|
||||
} else {
|
||||
showToast(this@ActPost, true, result.error)
|
||||
|
@ -2439,7 +2436,7 @@ class ActPost : AppCompatActivity(),
|
|||
}
|
||||
|
||||
override fun onPostExecute(result : String?) {
|
||||
progress.dismiss()
|
||||
progress.dismissSafe()
|
||||
|
||||
if(isCancelled || result == null) {
|
||||
// cancelled.
|
||||
|
|
|
@ -218,11 +218,7 @@ internal class DlgContextMenu(
|
|||
b.text = caption
|
||||
b.allCaps = false
|
||||
b.setOnClickListener {
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
span.onClick(contentTextView)
|
||||
}
|
||||
llLinks.addView(b, insPos ++)
|
||||
|
@ -445,12 +441,7 @@ internal class DlgContextMenu(
|
|||
}
|
||||
|
||||
override fun onClick(v : View) {
|
||||
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
|
||||
val pos = activity.nextPosition(column)
|
||||
|
||||
|
@ -870,11 +861,7 @@ internal class DlgContextMenu(
|
|||
|
||||
when(v.id) {
|
||||
R.id.btnFollow -> {
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
Action_Follow.followFromAnotherAccount(
|
||||
activity,
|
||||
activity.nextPosition(column),
|
||||
|
|
|
@ -46,14 +46,10 @@ object Action_Account {
|
|||
val data = result.data
|
||||
if(data is String) {
|
||||
// ブラウザ用URLが生成された
|
||||
try {
|
||||
val intent = Intent()
|
||||
intent.data = data.toUri()
|
||||
activity.startAccessTokenUpdate(intent)
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
} else if(data is JSONObject) {
|
||||
// インスタンスを確認できた
|
||||
when(action) {
|
||||
|
@ -94,9 +90,9 @@ object Action_Account {
|
|||
showToast(activity, false, R.string.server_confirmed)
|
||||
val pos = App1.getAppState(activity).column_list.size
|
||||
activity.addColumn(pos, a, Column.TYPE_LOCAL)
|
||||
dialog.dismissSafe()
|
||||
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
|
@ -189,16 +185,8 @@ object Action_Account {
|
|||
override fun handleResult(result : TootApiResult?) {
|
||||
val sa : SavedAccount? = null
|
||||
if(activity.afterAccountVerify(result, ta, sa, instance)) {
|
||||
try {
|
||||
dialog_host.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
try {
|
||||
dialog_create.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog_host.dismissSafe()
|
||||
dialog_create.dismissSafe()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -9,6 +9,7 @@ import jp.juggler.subwaytooter.api.entity.parseItem
|
|||
import jp.juggler.subwaytooter.dialog.DlgConfirm
|
||||
import jp.juggler.subwaytooter.dialog.DlgTextInput
|
||||
import jp.juggler.subwaytooter.table.SavedAccount
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.showToast
|
||||
import jp.juggler.util.toPostRequestBuilder
|
||||
import jp.juggler.util.toPutRequestBuilder
|
||||
|
@ -176,11 +177,7 @@ object Action_List {
|
|||
for(column in activity.app_state.column_list) {
|
||||
column.onListNameUpdated(access_info, list)
|
||||
}
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
} else {
|
||||
showToast(activity, false, result.error)
|
||||
}
|
||||
|
|
|
@ -443,11 +443,7 @@ object Action_User {
|
|||
ReportForm.showReportForm(activity, access_info, who, status) { dialog, comment, forward ->
|
||||
report(activity, access_info, who, status, comment, forward) {
|
||||
// 成功したらダイアログを閉じる
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// IllegalArgumentException がたまに出る
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.text.NumberFormat
|
|||
import jp.juggler.subwaytooter.App1
|
||||
import jp.juggler.subwaytooter.dialog.ProgressDialogEx
|
||||
import jp.juggler.subwaytooter.table.SavedAccount
|
||||
import jp.juggler.util.dismissSafe
|
||||
|
||||
/*
|
||||
非同期タスク(TootTask)を実行します。
|
||||
|
@ -180,7 +181,7 @@ class TootTaskRunner(
|
|||
|
||||
// ダイアログを閉じる
|
||||
private fun dismissProgress() {
|
||||
progress?.dismiss()
|
||||
progress?.dismissSafe()
|
||||
progress = null
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import jp.juggler.subwaytooter.table.AcctColor
|
|||
import jp.juggler.subwaytooter.table.SavedAccount
|
||||
import jp.juggler.subwaytooter.util.DialogInterfaceCallback
|
||||
import jp.juggler.subwaytooter.util.SavedAccountCallback
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.showToast
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
@ -144,7 +145,7 @@ object AccountPicker {
|
|||
b.setOnClickListener {
|
||||
isDialogClosed.set(true)
|
||||
callback(a)
|
||||
dialog.dismiss()
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
llAccounts.addView(b)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.TimePicker
|
|||
import jp.juggler.subwaytooter.R
|
||||
import java.util.*
|
||||
import android.provider.Settings.System.TIME_12_24
|
||||
import jp.juggler.util.dismissSafe
|
||||
|
||||
class DlgDateTime(
|
||||
val activity : Activity
|
||||
|
@ -84,7 +85,7 @@ class DlgDateTime(
|
|||
R.id.btnCancel -> dialog.cancel()
|
||||
|
||||
R.id.btnOk -> {
|
||||
dialog.dismiss()
|
||||
dialog.dismissSafe()
|
||||
callback(getTime())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import jp.juggler.subwaytooter.App1
|
|||
import jp.juggler.subwaytooter.R
|
||||
import jp.juggler.subwaytooter.api.entity.TootStatus
|
||||
import jp.juggler.subwaytooter.table.PostDraft
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.showToast
|
||||
import org.json.JSONObject
|
||||
|
||||
|
@ -36,7 +37,7 @@ class DlgDraftPicker : AdapterView.OnItemClickListener, AdapterView.OnItemLongCl
|
|||
val json = getPostDraft(position)?.json
|
||||
if(json != null) {
|
||||
callback(json)
|
||||
dialog.dismiss()
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import jp.juggler.subwaytooter.api.TootTaskRunner
|
|||
import jp.juggler.subwaytooter.api.entity.TootAttachment
|
||||
import jp.juggler.subwaytooter.view.FocusPointView
|
||||
import jp.juggler.util.LogCategory
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.showToast
|
||||
import jp.juggler.util.withCaption
|
||||
|
||||
|
@ -44,7 +45,7 @@ class DlgFocusPoint(val activity : Activity, val attachment : TootAttachment) :
|
|||
|
||||
override fun onClick(v : View) {
|
||||
when(v.id) {
|
||||
R.id.btnClose -> dialog.dismiss()
|
||||
R.id.btnClose -> dialog.dismissSafe()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,21 +106,13 @@ class DlgFocusPoint(val activity : Activity, val attachment : TootAttachment) :
|
|||
val bitmap = this.bitmap
|
||||
if(bitmap == null) {
|
||||
showToast(activity, true, result?.error ?: "?")
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
return
|
||||
}
|
||||
|
||||
if(activity.isFinishing) {
|
||||
bitmap.recycle()
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
|
||||
}
|
||||
dialog.dismissSafe()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -15,16 +15,19 @@ import jp.juggler.subwaytooter.action.Action_List
|
|||
import jp.juggler.subwaytooter.action.Action_ListMember
|
||||
import jp.juggler.subwaytooter.action.makeAccountListNonPseudo
|
||||
import jp.juggler.subwaytooter.api.*
|
||||
import jp.juggler.subwaytooter.api.entity.*
|
||||
import jp.juggler.subwaytooter.api.entity.EntityId
|
||||
import jp.juggler.subwaytooter.api.entity.TootAccount
|
||||
import jp.juggler.subwaytooter.api.entity.TootList
|
||||
import jp.juggler.subwaytooter.api.entity.parseList
|
||||
import jp.juggler.subwaytooter.table.AcctColor
|
||||
import jp.juggler.subwaytooter.table.SavedAccount
|
||||
import jp.juggler.subwaytooter.util.NetworkEmojiInvalidator
|
||||
import jp.juggler.subwaytooter.view.MyListView
|
||||
import jp.juggler.subwaytooter.view.MyNetworkImageView
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.getAttributeColor
|
||||
import jp.juggler.util.showToast
|
||||
import jp.juggler.util.toPostRequestBuilder
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
|
@ -51,10 +54,10 @@ class DlgListMember(
|
|||
this.account_list = makeAccountListNonPseudo(activity, null)
|
||||
this.target_user_full_acct = _list_owner.getFullAcct(who)
|
||||
|
||||
if(_list_owner.isPseudo) {
|
||||
this.list_owner = null
|
||||
this.list_owner = if(_list_owner.isPseudo) {
|
||||
null
|
||||
} else {
|
||||
this.list_owner = _list_owner
|
||||
_list_owner
|
||||
}
|
||||
|
||||
val view = activity.layoutInflater.inflate(R.layout.dlg_list_member, null, false)
|
||||
|
@ -73,7 +76,12 @@ class DlgListMember(
|
|||
btnListOwner.setOnClickListener(this)
|
||||
view.findViewById<View>(R.id.btnClose).setOnClickListener(this)
|
||||
|
||||
ivUser.setImageUrl(App1.pref, Styler.calcIconRound(ivUser.layoutParams), who.avatar_static, who.avatar)
|
||||
ivUser.setImageUrl(
|
||||
App1.pref,
|
||||
Styler.calcIconRound(ivUser.layoutParams),
|
||||
who.avatar_static,
|
||||
who.avatar
|
||||
)
|
||||
val user_name_invalidator = NetworkEmojiInvalidator(activity.handler, tvUserName)
|
||||
val name = who.decodeDisplayName(activity)
|
||||
tvUserName.text = name
|
||||
|
@ -82,35 +90,32 @@ class DlgListMember(
|
|||
|
||||
setListOwner(list_owner)
|
||||
|
||||
this.dialog = Dialog(activity)
|
||||
|
||||
val w = dialog.window
|
||||
if(w != null) {
|
||||
w.setFlags(0, Window.FEATURE_NO_TITLE)
|
||||
w.setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT
|
||||
dialog = Dialog(activity).apply{
|
||||
window?.apply{
|
||||
setFlags(0, Window.FEATURE_NO_TITLE)
|
||||
setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
dialog.setTitle(R.string.your_lists)
|
||||
dialog.setContentView(view)
|
||||
setTitle(R.string.your_lists)
|
||||
setContentView(view)
|
||||
}
|
||||
|
||||
fun show() {
|
||||
val w = dialog.window
|
||||
w?.setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT
|
||||
}
|
||||
|
||||
fun show() = dialog.apply{
|
||||
window?.setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
dialog.show()
|
||||
show()
|
||||
}
|
||||
|
||||
override fun onClick(v : View) {
|
||||
when(v.id) {
|
||||
|
||||
R.id.btnClose -> try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
}
|
||||
R.id.btnClose -> dialog.dismissSafe()
|
||||
|
||||
R.id.btnListOwner -> {
|
||||
AccountPicker.pick(
|
||||
|
@ -152,7 +157,12 @@ class DlgListMember(
|
|||
if(AcctColor.hasColorForeground(ac)) {
|
||||
btnListOwner.setTextColor(ac.color_fg)
|
||||
} else {
|
||||
btnListOwner.setTextColor(getAttributeColor(activity, android.R.attr.textColorPrimary))
|
||||
btnListOwner.setTextColor(
|
||||
getAttributeColor(
|
||||
activity,
|
||||
android.R.attr.textColorPrimary
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,54 +178,71 @@ class DlgListMember(
|
|||
return
|
||||
}
|
||||
|
||||
TootTaskRunner(activity).run(list_owner , object : TootTask {
|
||||
TootTaskRunner(activity).run(list_owner, object : TootTask {
|
||||
|
||||
var new_list : ArrayList<TootList>? = null
|
||||
|
||||
override fun background(client : TootApiClient) : TootApiResult? {
|
||||
|
||||
// リストに追加したいアカウントの自タンスでのアカウントIDを取得する
|
||||
var (result,ar) = client.syncAccountByAcct(list_owner,target_user_full_acct)
|
||||
val local_who = ar?.get() ?: return result
|
||||
val (r1, ar) = client.syncAccountByAcct(list_owner, target_user_full_acct)
|
||||
val local_who = ar?.get() ?: return r1
|
||||
|
||||
this@DlgListMember.local_who = local_who
|
||||
|
||||
if(list_owner.isMisskey){
|
||||
return if(list_owner.isMisskey) {
|
||||
// 今のmisskeyではリスト全スキャンしないとユーザの登録状況が分からない
|
||||
val params = list_owner.putMisskeyApiToken(JSONObject())
|
||||
result = client.request("/api/users/lists/list",params.toPostRequestBuilder())
|
||||
val jsonArray = result?.jsonArray ?:return result
|
||||
this.new_list = parseList(::TootList,TootParser(activity,list_owner),jsonArray)
|
||||
this.new_list?.forEach { list->
|
||||
list.isRegistered = null != list.userIds?.find { it == local_who.id }
|
||||
client.request(
|
||||
"/api/users/lists/list",
|
||||
list_owner
|
||||
.putMisskeyApiToken()
|
||||
.toPostRequestBuilder()
|
||||
)?.also { result ->
|
||||
this.new_list = parseList(
|
||||
::TootList,
|
||||
TootParser(activity, list_owner),
|
||||
result.jsonArray ?: return@also
|
||||
).apply {
|
||||
forEach { list ->
|
||||
list.isRegistered =
|
||||
null != list.userIds?.find { it == local_who.id }
|
||||
}
|
||||
}else{
|
||||
// リスト登録状況を取得
|
||||
result = client.request("/api/v1/accounts/" + local_who .id + "/lists")
|
||||
var jsonArray = result?.jsonArray ?:return result
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// 結果を解釈する
|
||||
val set_registered = HashSet<EntityId>()
|
||||
for(a in parseList(::TootList,TootParser(activity,list_owner),jsonArray)) {
|
||||
set_registered.add(a.id)
|
||||
|
||||
// メンバーを指定してリスト登録状況を取得
|
||||
client.request(
|
||||
"/api/v1/accounts/${local_who.id}/lists"
|
||||
)?.also { result ->
|
||||
val jsonArray = result.jsonArray ?: return result
|
||||
parseList(
|
||||
::TootList,
|
||||
TootParser(activity, list_owner),
|
||||
jsonArray
|
||||
).forEach {
|
||||
set_registered.add(it.id)
|
||||
}
|
||||
}
|
||||
|
||||
// リスト一覧を取得
|
||||
result = client.request("/api/v1/lists")
|
||||
jsonArray = result?.jsonArray ?: return result
|
||||
client.request("/api/v1/lists")?.also { result ->
|
||||
this.new_list = parseList(
|
||||
::TootList,
|
||||
TootParser(activity, list_owner),
|
||||
result.jsonArray ?: return@also
|
||||
).apply {
|
||||
|
||||
val new_list = parseList(::TootList,TootParser(activity,list_owner),jsonArray)
|
||||
new_list.sort()
|
||||
sort()
|
||||
|
||||
this.new_list = new_list
|
||||
|
||||
// isRegistered を設定する
|
||||
for(a in new_list) {
|
||||
if(set_registered.contains(a.id)) a.isRegistered = true
|
||||
forEach {
|
||||
it.isRegistered = set_registered.contains(it.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override fun handleResult(result : TootApiResult?) {
|
||||
|
@ -224,7 +251,7 @@ class DlgListMember(
|
|||
result ?: return // cancelled.
|
||||
|
||||
val error = result.error
|
||||
if( error?.isNotEmpty() == true && result.response?.code() == 404 ) {
|
||||
if(error?.isNotEmpty() == true && result.response?.code() == 404) {
|
||||
showToast(activity, true, result.error)
|
||||
}
|
||||
|
||||
|
@ -245,7 +272,11 @@ class DlgListMember(
|
|||
}
|
||||
|
||||
private fun openListCreator() {
|
||||
DlgTextInput.show(activity, activity.getString(R.string.list_create), null, object : DlgTextInput.Callback {
|
||||
DlgTextInput.show(
|
||||
activity,
|
||||
activity.getString(R.string.list_create),
|
||||
null,
|
||||
object : DlgTextInput.Callback {
|
||||
|
||||
override fun onEmptyError() {
|
||||
showToast(activity, false, R.string.list_name_empty)
|
||||
|
@ -259,15 +290,14 @@ class DlgListMember(
|
|||
return
|
||||
}
|
||||
|
||||
Action_List.create(activity, list_owner , text, object : Action_List.CreateCallback {
|
||||
Action_List.create(
|
||||
activity,
|
||||
list_owner,
|
||||
text,
|
||||
object : Action_List.CreateCallback {
|
||||
override fun onCreated(list : TootList) {
|
||||
try {
|
||||
dialog.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
}
|
||||
|
||||
dialog.dismissSafe()
|
||||
loadLists()
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -302,7 +332,7 @@ class DlgListMember(
|
|||
}
|
||||
|
||||
override fun getView(position : Int, viewOld : View?, parent : ViewGroup) : View {
|
||||
val view:View
|
||||
val view : View
|
||||
val o = getItem(position)
|
||||
when(o) {
|
||||
is TootList -> {
|
||||
|
@ -311,31 +341,44 @@ class DlgListMember(
|
|||
view = viewOld
|
||||
holder = view.tag as VH_List
|
||||
} else {
|
||||
view = activity.layoutInflater.inflate(R.layout.lv_list_member_list, parent, false)
|
||||
view = activity.layoutInflater.inflate(
|
||||
R.layout.lv_list_member_list,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
holder = VH_List(view)
|
||||
view .tag = holder
|
||||
view.tag = holder
|
||||
}
|
||||
holder.bind(o)
|
||||
}
|
||||
|
||||
is ErrorItem -> {
|
||||
val holder : VH_Error
|
||||
if(viewOld != null) {
|
||||
view = viewOld
|
||||
holder = view.tag as VH_Error
|
||||
} else {
|
||||
view = activity.layoutInflater.inflate(R.layout.lv_list_member_error, parent, false)
|
||||
view = activity.layoutInflater.inflate(
|
||||
R.layout.lv_list_member_error,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
holder = VH_Error(view)
|
||||
view .tag = holder
|
||||
view.tag = holder
|
||||
}
|
||||
holder.bind(o)
|
||||
}
|
||||
else -> view = activity.layoutInflater.inflate(R.layout.lv_list_member_error, parent, false)
|
||||
|
||||
else -> view =
|
||||
activity.layoutInflater.inflate(R.layout.lv_list_member_error, parent, false)
|
||||
}
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
internal inner class VH_List(view : View) : CompoundButton.OnCheckedChangeListener, Action_ListMember.Callback {
|
||||
internal inner class VH_List(view : View) : CompoundButton.OnCheckedChangeListener,
|
||||
Action_ListMember.Callback {
|
||||
|
||||
private val cbItem : CheckBox
|
||||
private var bBusy : Boolean = false
|
||||
var item : TootList? = null
|
||||
|
@ -373,13 +416,13 @@ class DlgListMember(
|
|||
return
|
||||
}
|
||||
|
||||
val item = this.item ?:return
|
||||
val item = this.item ?: return
|
||||
|
||||
// 状態をサーバに伝える
|
||||
if(isChecked) {
|
||||
Action_ListMember.add(activity, list_owner , item.id, local_who , callback = this)
|
||||
Action_ListMember.add(activity, list_owner, item.id, local_who, callback = this)
|
||||
} else {
|
||||
Action_ListMember.delete(activity, list_owner , item.id, local_who , this)
|
||||
Action_ListMember.delete(activity, list_owner, item.id, local_who, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,11 +435,7 @@ class DlgListMember(
|
|||
}
|
||||
|
||||
internal inner class VH_Error(view : View) {
|
||||
private val tvError : TextView
|
||||
|
||||
init {
|
||||
this.tvError = view.findViewById(R.id.tvError)
|
||||
}
|
||||
private val tvError : TextView = view.findViewById(R.id.tvError)
|
||||
|
||||
fun bind(o : ErrorItem) {
|
||||
this.tvError.text = o.message
|
||||
|
|
|
@ -11,6 +11,7 @@ import jp.juggler.subwaytooter.ActMain
|
|||
import jp.juggler.subwaytooter.App1
|
||||
import jp.juggler.subwaytooter.R
|
||||
import jp.juggler.util.LogCategory
|
||||
import jp.juggler.util.dismissSafe
|
||||
import jp.juggler.util.showToast
|
||||
import net.glxn.qrgen.android.QRCode
|
||||
|
||||
|
@ -48,7 +49,7 @@ object DlgQRCode {
|
|||
}
|
||||
|
||||
override fun onPostExecute(result : Bitmap?) {
|
||||
progress.dismiss()
|
||||
progress.dismissSafe()
|
||||
if(result != null) {
|
||||
callback.onQrCode(result)
|
||||
}
|
||||
|
|
|
@ -11,16 +11,8 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.widget.*
|
||||
|
||||
import com.astuetz.PagerSlidingTabStrip
|
||||
import jp.juggler.emoji.EmojiMap201709
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
|
||||
import jp.juggler.subwaytooter.App1
|
||||
import jp.juggler.subwaytooter.Pref
|
||||
import jp.juggler.subwaytooter.R
|
||||
|
@ -28,9 +20,9 @@ import jp.juggler.subwaytooter.api.entity.CustomEmoji
|
|||
import jp.juggler.subwaytooter.put
|
||||
import jp.juggler.subwaytooter.view.MyViewPager
|
||||
import jp.juggler.subwaytooter.view.NetworkEmojiView
|
||||
import jp.juggler.util.LogCategory
|
||||
import jp.juggler.util.parseString
|
||||
import jp.juggler.util.toJsonArray
|
||||
import jp.juggler.util.*
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
class EmojiPicker(
|
||||
|
@ -201,9 +193,9 @@ class EmojiPicker(
|
|||
onPageSelected(0)
|
||||
|
||||
// カスタム絵文字をロードする
|
||||
if( instance != null && instance.isNotEmpty()) {
|
||||
if(instance != null && instance.isNotEmpty()) {
|
||||
setCustomEmojiList(
|
||||
App1.custom_emoji_lister.getList(instance,isMisskey=isMisskey) {
|
||||
App1.custom_emoji_lister.getList(instance, isMisskey = isMisskey) {
|
||||
setCustomEmojiList(it) // ロード完了時に呼ばれる
|
||||
}
|
||||
)
|
||||
|
@ -246,11 +238,11 @@ class EmojiPicker(
|
|||
}
|
||||
|
||||
override fun onPageSelected(position : Int) {
|
||||
try{
|
||||
val hasSkinTone =page_list[position].hasSkinTone
|
||||
try {
|
||||
val hasSkinTone = page_list[position].hasSkinTone
|
||||
val visibility = if(hasSkinTone) View.VISIBLE else View.INVISIBLE
|
||||
ibSkinTone.forEach { it.visibility = visibility }
|
||||
}catch(ex:Throwable){
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +331,7 @@ class EmojiPicker(
|
|||
inner class EmojiPickerPageViewHolder(activity : Activity, root : View) : BaseAdapter(),
|
||||
AdapterView.OnItemClickListener {
|
||||
|
||||
val gridView : GridView
|
||||
private val gridView : GridView
|
||||
private val wh : Int
|
||||
|
||||
private var page : EmojiPickerPage? = null
|
||||
|
@ -398,9 +390,9 @@ class EmojiPicker(
|
|||
}
|
||||
view.tag = item
|
||||
if(view is ImageView) {
|
||||
val name = if( page.hasSkinTone ){
|
||||
val name = if(page.hasSkinTone) {
|
||||
applySkinTone(item.name)
|
||||
}else{
|
||||
} else {
|
||||
item.name
|
||||
}
|
||||
|
||||
|
@ -439,10 +431,10 @@ class EmojiPicker(
|
|||
// 普通の絵文字
|
||||
EmojiMap201709.sShortNameToImageId[name] ?: return
|
||||
|
||||
if( page.hasSkinTone ){
|
||||
if(page.hasSkinTone) {
|
||||
val sv = applySkinTone(name)
|
||||
if(EmojiMap201709.sShortNameToImageId[sv]!=null){
|
||||
name=sv
|
||||
if(EmojiMap201709.sShortNameToImageId[sv] != null) {
|
||||
name = sv
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,32 +447,22 @@ class EmojiPicker(
|
|||
// name はスキントーン適用済みであること
|
||||
internal fun selected(name : String, instance : String?) {
|
||||
|
||||
dialog.dismiss()
|
||||
dialog.dismissSafe()
|
||||
|
||||
val pref = App1.pref
|
||||
|
||||
// Recentをロード(他インスタンスの絵文字を含む)
|
||||
val pref = App1.pref
|
||||
val list = ArrayList<JSONObject>()
|
||||
val sv = Pref.spEmojiPickerRecent(pref)
|
||||
if(sv.isNotEmpty()) {
|
||||
try {
|
||||
val array = sv.toJsonArray()
|
||||
var i = 0
|
||||
val ie = array.length()
|
||||
while(i < ie) {
|
||||
val item = array.optJSONObject(i)
|
||||
if(item != null) list.add(item)
|
||||
++ i
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
}
|
||||
val list = try {
|
||||
Pref.spEmojiPickerRecent(pref).toJsonArray().toObjectList()
|
||||
} catch(ignored : Throwable) {
|
||||
ArrayList<JSONObject>()
|
||||
}
|
||||
|
||||
// 選択された絵文字と同じ項目を除去
|
||||
// 項目が増えすぎたら減らす
|
||||
run {
|
||||
val it = list.iterator()
|
||||
var nCount = 0
|
||||
val it = list.iterator()
|
||||
while(it.hasNext()) {
|
||||
val item = it.next()
|
||||
if(name == item.parseString("name")
|
||||
|
@ -494,21 +476,15 @@ class EmojiPicker(
|
|||
}
|
||||
|
||||
// 先頭に項目を追加
|
||||
try {
|
||||
val item = JSONObject()
|
||||
item.put("name", name)
|
||||
if(instance != null) item.put("instance", instance)
|
||||
list.add(0, item)
|
||||
} catch(ignored : Throwable) {
|
||||
}
|
||||
list.add(0, JSONObject().apply {
|
||||
put("name", name)
|
||||
if(instance != null) put("instance", instance)
|
||||
})
|
||||
|
||||
// 保存する
|
||||
try {
|
||||
val array = JSONArray()
|
||||
for(item in list) {
|
||||
array.put(item)
|
||||
}
|
||||
App1.pref.edit().put(Pref.spEmojiPickerRecent, array.toString()).apply()
|
||||
val sv = list.toJsonArray().toString()
|
||||
App1.pref.edit().put(Pref.spEmojiPickerRecent, sv).apply()
|
||||
} catch(ignored : Throwable) {
|
||||
|
||||
}
|
||||
|
@ -532,15 +508,15 @@ class EmojiPicker(
|
|||
private fun Int.validPage() = this >= 0 && this < page_list.size
|
||||
|
||||
private fun getPage(idx : Int) : EmojiPickerPage? {
|
||||
return if(idx.validPage() ) page_list[idx] else null
|
||||
return if(idx.validPage()) page_list[idx] else null
|
||||
}
|
||||
|
||||
fun getPageViewHolder(idx : Int) : EmojiPickerPageViewHolder? {
|
||||
return if(idx.validPage() ) holder_list.get(idx) else null
|
||||
return if(idx.validPage()) holder_list.get(idx) else null
|
||||
}
|
||||
|
||||
inline fun eachViewHolder(block : (Int, EmojiPickerPageViewHolder) -> Unit) {
|
||||
for(i in 0 until page_list.size ){
|
||||
for(i in 0 until page_list.size) {
|
||||
val vh = holder_list.get(i) ?: continue
|
||||
block(i, vh)
|
||||
}
|
||||
|
|
|
@ -10,18 +10,4 @@ class ProgressDialogEx(context : Context) : ProgressDialog(context) {
|
|||
const val STYLE_SPINNER = ProgressDialog.STYLE_SPINNER
|
||||
const val STYLE_HORIZONTAL = ProgressDialog.STYLE_HORIZONTAL
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
try {
|
||||
super.dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// java.lang.IllegalArgumentException:
|
||||
// at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
|
||||
// at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
|
||||
// at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
|
||||
// at android.app.Dialog.dismissDialog(Dialog.java:341)
|
||||
// at android.app.Dialog.dismiss(Dialog.java:324)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package jp.juggler.util
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.ColorFilter
|
||||
|
@ -272,3 +274,11 @@ fun CharSequence.copyToClipboard(context:Context) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
fun DialogInterface.dismissSafe(){
|
||||
try {
|
||||
dismiss()
|
||||
} catch(ignored : Throwable) {
|
||||
// 非同期処理の後などではDialogがWindowTokenを失っている場合があり、IllegalArgumentException がたまに出る
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue