2018-01-04 19:52:25 +01:00
|
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.app.Dialog
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
|
import android.content.pm.PackageManager
|
2019-01-17 20:40:51 +01:00
|
|
|
|
import android.content.res.ColorStateList
|
2019-11-14 07:37:45 +01:00
|
|
|
|
import android.content.res.Configuration
|
2018-01-04 19:52:25 +01:00
|
|
|
|
import android.graphics.Typeface
|
|
|
|
|
import android.net.Uri
|
2019-09-12 15:43:11 +02:00
|
|
|
|
import android.os.*
|
2018-01-04 19:52:25 +01:00
|
|
|
|
import android.text.InputType
|
|
|
|
|
import android.text.Spannable
|
|
|
|
|
import android.text.SpannableStringBuilder
|
|
|
|
|
import android.util.JsonReader
|
2019-12-15 20:12:57 +01:00
|
|
|
|
import android.view.*
|
2018-01-04 19:52:25 +01:00
|
|
|
|
import android.view.inputmethod.EditorInfo
|
2018-10-28 14:08:10 +01:00
|
|
|
|
import android.widget.*
|
2019-03-13 19:06:56 +01:00
|
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
|
import androidx.core.view.GravityCompat
|
2019-08-23 11:38:47 +02:00
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout
|
2019-03-13 19:06:56 +01:00
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2019-08-23 11:38:47 +02:00
|
|
|
|
import androidx.viewpager.widget.ViewPager
|
2018-01-04 19:52:25 +01:00
|
|
|
|
import jp.juggler.subwaytooter.action.*
|
2018-01-21 17:47:13 +01:00
|
|
|
|
import jp.juggler.subwaytooter.api.*
|
2019-04-04 04:10:42 +02:00
|
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2019-09-30 13:02:39 +02:00
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootStatus.Companion.findStatusIdFromUrl
|
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootTag.Companion.findHashtagFromUrl
|
2020-04-07 06:52:54 +02:00
|
|
|
|
import jp.juggler.subwaytooter.dialog.AccountPicker
|
|
|
|
|
import jp.juggler.subwaytooter.dialog.ActionsDialog
|
|
|
|
|
import jp.juggler.subwaytooter.dialog.DlgQuickTootMenu
|
|
|
|
|
import jp.juggler.subwaytooter.dialog.DlgTextInput
|
2018-01-04 19:52:25 +01:00
|
|
|
|
import jp.juggler.subwaytooter.span.MyClickableSpan
|
2018-10-28 14:08:10 +01:00
|
|
|
|
import jp.juggler.subwaytooter.table.AcctColor
|
|
|
|
|
import jp.juggler.subwaytooter.table.SavedAccount
|
2019-12-17 19:11:19 +01:00
|
|
|
|
import jp.juggler.subwaytooter.util.*
|
2018-11-12 02:34:15 +01:00
|
|
|
|
import jp.juggler.subwaytooter.view.*
|
2018-12-01 00:02:18 +01:00
|
|
|
|
import jp.juggler.util.*
|
2020-04-07 06:52:54 +02:00
|
|
|
|
import kotlinx.coroutines.delay
|
2018-10-28 14:08:10 +01:00
|
|
|
|
import org.apache.commons.io.IOUtils
|
2019-01-20 22:04:57 +01:00
|
|
|
|
import org.jetbrains.anko.backgroundDrawable
|
2018-10-28 14:08:10 +01:00
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.FileInputStream
|
|
|
|
|
import java.io.FileOutputStream
|
|
|
|
|
import java.io.InputStreamReader
|
|
|
|
|
import java.lang.ref.WeakReference
|
|
|
|
|
import java.util.*
|
2018-09-20 18:41:04 +02:00
|
|
|
|
import java.util.zip.ZipInputStream
|
2018-11-24 08:04:42 +01:00
|
|
|
|
import kotlin.math.abs
|
2019-10-09 17:09:52 +02:00
|
|
|
|
import kotlin.math.max
|
2018-09-17 20:06:15 +02:00
|
|
|
|
import kotlin.math.min
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
class ActMain : AsyncActivity()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
, Column.Callback
|
2019-08-23 11:38:47 +02:00
|
|
|
|
, View.OnClickListener
|
|
|
|
|
, ViewPager.OnPageChangeListener
|
|
|
|
|
, DrawerLayout.DrawerListener {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
class PhoneEnv {
|
|
|
|
|
internal lateinit var pager : MyViewPager
|
|
|
|
|
internal lateinit var pager_adapter : ColumnPagerAdapter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TabletEnv {
|
|
|
|
|
internal lateinit var tablet_pager : RecyclerView
|
|
|
|
|
internal lateinit var tablet_pager_adapter : TabletColumnPagerAdapter
|
|
|
|
|
internal lateinit var tablet_layout_manager : LinearLayoutManager
|
|
|
|
|
internal lateinit var tablet_snap_helper : GravitySnapHelper
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
val log = LogCategory("ActMain")
|
|
|
|
|
|
|
|
|
|
// リザルト
|
|
|
|
|
const val RESULT_APP_DATA_IMPORT = Activity.RESULT_FIRST_USER
|
|
|
|
|
|
|
|
|
|
// リクエスト
|
|
|
|
|
const val REQUEST_CODE_COLUMN_LIST = 1
|
|
|
|
|
const val REQUEST_CODE_ACCOUNT_SETTING = 2
|
|
|
|
|
const val REQUEST_APP_ABOUT = 3
|
|
|
|
|
const val REQUEST_CODE_NICKNAME = 4
|
|
|
|
|
const val REQUEST_CODE_POST = 5
|
|
|
|
|
const val REQUEST_CODE_COLUMN_COLOR = 6
|
|
|
|
|
const val REQUEST_CODE_APP_SETTING = 7
|
|
|
|
|
const val REQUEST_CODE_TEXT = 8
|
2019-12-13 15:48:38 +01:00
|
|
|
|
const val REQUEST_CODE_LANGUAGE_FILTER = 9
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
const val COLUMN_WIDTH_MIN_DP = 300
|
|
|
|
|
|
|
|
|
|
const val STATE_CURRENT_PAGE = "current_page"
|
|
|
|
|
|
2018-11-02 01:09:31 +01:00
|
|
|
|
// 外部からインテントを受信した後、アカウント選択中に画面回転したらアカウント選択からやり直す
|
2018-01-04 19:52:25 +01:00
|
|
|
|
internal var sent_intent2 : Intent? = null
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// アプリ設定のキャッシュ
|
2019-01-08 03:02:02 +01:00
|
|
|
|
var boostButtonSize = 1
|
|
|
|
|
var replyIconSize = 1
|
2019-01-11 10:47:30 +01:00
|
|
|
|
var headerIconSize = 1
|
2019-01-15 14:43:56 +01:00
|
|
|
|
var stripIconSize = 1
|
2018-08-22 01:35:54 +02:00
|
|
|
|
var timeline_font : Typeface = Typeface.DEFAULT
|
|
|
|
|
var timeline_font_bold : Typeface = Typeface.DEFAULT_BOLD
|
2019-09-30 13:02:39 +02:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private fun Float.clipFontSize() : Float =
|
|
|
|
|
if(isNaN()) this else max(1f, this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// アプリ設定のキャッシュ
|
|
|
|
|
var density = 0f
|
|
|
|
|
var acct_pad_lr = 0
|
|
|
|
|
var timeline_font_size_sp = Float.NaN
|
|
|
|
|
var acct_font_size_sp = Float.NaN
|
|
|
|
|
var notification_tl_font_size_sp = Float.NaN
|
|
|
|
|
var header_text_size_sp = Float.NaN
|
2019-12-15 16:34:46 +01:00
|
|
|
|
var timeline_spacing : Float? = null
|
2019-10-09 17:09:52 +02:00
|
|
|
|
var avatarIconSize : Int = 0
|
|
|
|
|
var notificationTlIconSize : Int = 0
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// onResume() .. onPause() の間なら真
|
|
|
|
|
private var isResumed = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// onStart() .. onStop() の間なら真
|
|
|
|
|
private var isStart_ = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// onActivityResultで設定されてonResumeで消化される
|
|
|
|
|
// 状態保存の必要なし
|
2020-02-02 15:19:57 +01:00
|
|
|
|
private var posted_acct : Acct? = null // acctAscii
|
2018-08-18 12:58:14 +02:00
|
|
|
|
private var posted_status_id : EntityId? = null
|
|
|
|
|
private var posted_reply_id : EntityId? = null
|
|
|
|
|
private var posted_redraft_id : EntityId? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// 画面上のUI操作で生成されて
|
|
|
|
|
// onPause,onPageDestroy 等のタイミングで閉じられる
|
|
|
|
|
// 状態保存の必要なし
|
2018-10-28 14:08:10 +01:00
|
|
|
|
internal var listItemPopup : StatusButtonsPopup? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private var phoneEnv : PhoneEnv? = null
|
|
|
|
|
private var tabletEnv : TabletEnv? = null
|
|
|
|
|
|
|
|
|
|
private var nScreenColumn : Int = 0
|
|
|
|
|
private var nColumnWidth : Int = 0 // dividerの幅を含む
|
|
|
|
|
|
|
|
|
|
private var nAutoCwCellWidth = 0
|
|
|
|
|
private var nAutoCwLines = 0
|
|
|
|
|
|
|
|
|
|
private var dlgPrivacyPolicy : WeakReference<Dialog>? = null
|
|
|
|
|
|
|
|
|
|
private var quickTootVisibility : TootVisibility = TootVisibility.AccountSetting
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// 変更しない変数(lateinit)
|
|
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
|
private lateinit var llQuickTootBar : LinearLayout
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private lateinit var etQuickToot : MyEditText
|
|
|
|
|
private lateinit var btnQuickToot : ImageButton
|
|
|
|
|
private lateinit var btnQuickTootMenu : ImageButton
|
2018-01-04 19:52:25 +01:00
|
|
|
|
private lateinit var llEmpty : View
|
|
|
|
|
private lateinit var llColumnStrip : ColumnStripLinearLayout
|
|
|
|
|
private lateinit var svColumnStrip : HorizontalScrollView
|
|
|
|
|
private lateinit var btnMenu : ImageButton
|
|
|
|
|
private lateinit var btnToot : ImageButton
|
|
|
|
|
private lateinit var vFooterDivider1 : View
|
|
|
|
|
private lateinit var vFooterDivider2 : View
|
|
|
|
|
|
2020-02-05 09:18:28 +01:00
|
|
|
|
lateinit var drawer : MyDrawerLayout
|
2018-01-17 18:39:16 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
lateinit var post_helper : PostHelper
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
lateinit var pref : SharedPreferences
|
|
|
|
|
lateinit var handler : Handler
|
|
|
|
|
lateinit var app_state : AppState
|
2019-06-04 01:24:54 +02:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// 変更しない変数
|
2018-01-17 02:16:26 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val follow_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.follow_succeeded)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val unfollow_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.unfollow_succeeded)
|
|
|
|
|
}
|
|
|
|
|
val cancel_follow_request_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.follow_request_cancelled)
|
|
|
|
|
}
|
2019-12-15 16:34:46 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val favourite_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.favourite_succeeded)
|
|
|
|
|
}
|
|
|
|
|
val unfavourite_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.unfavourite_succeeded)
|
|
|
|
|
}
|
2019-12-15 16:34:46 +01:00
|
|
|
|
|
2019-11-14 01:51:17 +01:00
|
|
|
|
val bookmark_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.bookmark_succeeded)
|
|
|
|
|
}
|
|
|
|
|
val unbookmark_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.unbookmark_succeeded)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val boost_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.boost_succeeded)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-01-17 02:16:26 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val unboost_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.unboost_succeeded)
|
2018-01-10 16:47:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val reaction_complete_callback : EmptyCallback = {
|
|
|
|
|
showToast(this@ActMain, false, R.string.reaction_succeeded)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// 相対時刻の表記を定期的に更新する
|
|
|
|
|
private val proc_updateRelativeTime = object : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
handler.removeCallbacks(this)
|
|
|
|
|
if(! isStart_) return
|
|
|
|
|
if(Pref.bpRelativeTimestamp(pref)) {
|
|
|
|
|
for(c in app_state.column_list) {
|
|
|
|
|
c.fireRelativeTime()
|
|
|
|
|
}
|
|
|
|
|
handler.postDelayed(this, 10000L)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-12-22 17:55:24 +01:00
|
|
|
|
private val link_click_listener : (View, MyClickableSpan) -> Unit = { viewClicked, span ->
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-12-22 17:55:24 +01:00
|
|
|
|
val linkInfo = span.linkInfo
|
2018-01-04 19:52:25 +01:00
|
|
|
|
var view = viewClicked
|
|
|
|
|
var column : Column? = null
|
2019-04-04 04:10:42 +02:00
|
|
|
|
var whoRef : TootAccountRef? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
val tag = view.tag
|
|
|
|
|
if(tag is ItemViewHolder) {
|
|
|
|
|
column = tag.column
|
2019-04-04 04:10:42 +02:00
|
|
|
|
whoRef = tag.getAccount()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
break
|
2018-01-21 13:46:36 +01:00
|
|
|
|
} else if(tag is ViewHolderItem) {
|
2018-01-19 10:27:35 +01:00
|
|
|
|
column = tag.ivh.column
|
2019-04-04 04:10:42 +02:00
|
|
|
|
whoRef = tag.ivh.getAccount()
|
2018-01-19 10:27:35 +01:00
|
|
|
|
break
|
2020-01-27 16:41:18 +01:00
|
|
|
|
} else if(tag is ColumnViewHolder) {
|
|
|
|
|
column = tag.column
|
|
|
|
|
whoRef = null
|
|
|
|
|
break
|
2018-01-19 10:27:35 +01:00
|
|
|
|
} else if(tag is ViewHolderHeaderBase) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
column = tag.column
|
2019-04-04 04:10:42 +02:00
|
|
|
|
whoRef = tag.getAccount()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
break
|
|
|
|
|
} else if(tag is TabletColumnViewHolder) {
|
|
|
|
|
column = tag.columnViewHolder.column
|
|
|
|
|
break
|
|
|
|
|
} else {
|
|
|
|
|
val parent = view.parent
|
|
|
|
|
if(parent is View) {
|
|
|
|
|
view = parent
|
|
|
|
|
} else {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val pos = nextPosition(column)
|
|
|
|
|
val access_info = column?.access_info
|
|
|
|
|
|
|
|
|
|
var tag_list : ArrayList<String>? = null
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
val cs = (viewClicked as TextView).text
|
|
|
|
|
if(cs is Spannable) {
|
|
|
|
|
for(s in cs.getSpans(0, cs.length, MyClickableSpan::class.java)) {
|
2019-12-22 17:55:24 +01:00
|
|
|
|
val li = s.linkInfo
|
|
|
|
|
val pair = li.url.findHashtagFromUrl()
|
2019-09-30 13:02:39 +02:00
|
|
|
|
if(pair != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(tag_list == null) tag_list = ArrayList()
|
2019-12-22 17:55:24 +01:00
|
|
|
|
tag_list.add(if(li.text.startsWith('#')) li.text else "#${pair.first}")
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 19:09:36 +01:00
|
|
|
|
ChromeTabOpener(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
pos,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
linkInfo.url,
|
2018-01-18 19:09:36 +01:00
|
|
|
|
accessInfo = access_info,
|
2019-04-04 04:10:42 +02:00
|
|
|
|
tagList = tag_list,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
whoRef = whoRef,
|
|
|
|
|
linkInfo = linkInfo
|
2018-01-18 19:09:36 +01:00
|
|
|
|
).open()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private val dlgQuickTootMenu = DlgQuickTootMenu(this, object : DlgQuickTootMenu.Callback {
|
|
|
|
|
|
|
|
|
|
override var visibility : TootVisibility
|
|
|
|
|
get() = quickTootVisibility
|
|
|
|
|
set(value) {
|
|
|
|
|
if(value != quickTootVisibility) {
|
|
|
|
|
quickTootVisibility = value
|
|
|
|
|
pref.edit().put(Pref.spQuickTootVisibility, value.id.toString()).apply()
|
2018-01-20 07:51:14 +01:00
|
|
|
|
}
|
2019-10-09 17:09:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onMacro(text : String) {
|
|
|
|
|
val editable = etQuickToot.text
|
|
|
|
|
if(editable?.isNotEmpty() == true) {
|
|
|
|
|
val start = etQuickToot.selectionStart
|
|
|
|
|
val end = etQuickToot.selectionEnd
|
|
|
|
|
editable.replace(start, end, text)
|
|
|
|
|
etQuickToot.requestFocus()
|
|
|
|
|
etQuickToot.setSelection(start + text.length)
|
|
|
|
|
} else {
|
|
|
|
|
etQuickToot.setText(text)
|
|
|
|
|
etQuickToot.requestFocus()
|
|
|
|
|
etQuickToot.setSelection(text.length)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-09 17:09:52 +02:00
|
|
|
|
})
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val viewPool = RecyclerView.RecycledViewPool()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// 読み取り専用のプロパティ
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
override val isActivityStart : Boolean
|
|
|
|
|
get() = isStart_
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// スマホモードなら現在のカラムを、タブレットモードなら-1Lを返す
|
|
|
|
|
// (カラム一覧画面のデフォルト選択位置に使われる)
|
|
|
|
|
val currentColumn : Int
|
2018-01-10 16:47:35 +01:00
|
|
|
|
get() = phoneTab(
|
2018-11-12 18:19:57 +01:00
|
|
|
|
{ it.pager.currentItem },
|
|
|
|
|
{ - 1 }
|
2018-01-10 16:47:35 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 新しいカラムをどこに挿入するか
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// 現在のページの次の位置か、終端
|
2019-08-23 14:50:04 +02:00
|
|
|
|
val defaultInsertPosition : Int
|
2018-01-10 16:47:35 +01:00
|
|
|
|
get() = phoneTab(
|
2018-11-12 18:19:57 +01:00
|
|
|
|
{ it.pager.currentItem + 1 },
|
|
|
|
|
{ Integer.MAX_VALUE }
|
2018-01-10 16:47:35 +01:00
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private val TabletEnv.visibleColumnsIndices : IntRange
|
2019-10-09 17:21:58 +02:00
|
|
|
|
get() {
|
2019-10-09 17:09:52 +02:00
|
|
|
|
var vs = tablet_layout_manager.findFirstVisibleItemPosition()
|
|
|
|
|
var ve = tablet_layout_manager.findLastVisibleItemPosition()
|
|
|
|
|
if(vs == RecyclerView.NO_POSITION || ve == RecyclerView.NO_POSITION) {
|
|
|
|
|
return IntRange(- 1, - 2) // empty and less than zero
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val child = tablet_layout_manager.findViewByPosition(vs)
|
|
|
|
|
val slide_ratio =
|
|
|
|
|
clipRange(0f, 1f, abs((child?.left ?: 0) / nColumnWidth.toFloat()))
|
|
|
|
|
if(slide_ratio >= 0.95f) {
|
|
|
|
|
++ vs
|
|
|
|
|
++ ve
|
|
|
|
|
}
|
|
|
|
|
return IntRange(vs, min(ve, vs + nScreenColumn - 1))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val TabletEnv.visibleColumns : List<Column>
|
|
|
|
|
get() = visibleColumnsIndices
|
2019-10-09 17:21:58 +02:00
|
|
|
|
.mapNotNull {
|
|
|
|
|
try {
|
2019-10-09 17:09:52 +02:00
|
|
|
|
app_state.column_list[it]
|
2019-10-09 17:21:58 +02:00
|
|
|
|
} catch(ex : Throwable) {
|
2019-10-09 17:09:52 +02:00
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// デフォルトの投稿先アカウントを探す。アカウント選択が必要な状況ならnull
|
|
|
|
|
val currentPostTarget : SavedAccount?
|
|
|
|
|
get() = phoneTab(
|
|
|
|
|
{ env ->
|
|
|
|
|
val c = env.pager_adapter.getColumn(env.pager.currentItem)
|
|
|
|
|
return when {
|
|
|
|
|
c == null || c.access_info.isPseudo -> null
|
|
|
|
|
else -> c.access_info
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ env ->
|
|
|
|
|
|
|
|
|
|
val db_id = Pref.lpTabletTootDefaultAccount(App1.pref)
|
|
|
|
|
if(db_id != - 1L) {
|
|
|
|
|
val a = SavedAccount.loadAccount(this@ActMain, db_id)
|
|
|
|
|
if(a != null && ! a.isPseudo) return a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val accounts = ArrayList<SavedAccount>()
|
|
|
|
|
for(c in env.visibleColumns) {
|
|
|
|
|
try {
|
|
|
|
|
val a = c.access_info
|
|
|
|
|
// 画面内に疑似アカウントがあれば常にアカウント選択が必要
|
|
|
|
|
if(a.isPseudo) {
|
|
|
|
|
accounts.clear()
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
// 既出でなければ追加する
|
2020-02-02 07:25:08 +01:00
|
|
|
|
if(null == accounts.find { it == a }) accounts.add(a)
|
2019-10-09 17:09:52 +02:00
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-10 14:42:37 +01:00
|
|
|
|
return when(accounts.size) {
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// 候補が1つだけならアカウント選択は不要
|
2020-01-10 14:42:37 +01:00
|
|
|
|
1 -> accounts.first()
|
2019-10-09 17:09:52 +02:00
|
|
|
|
// 候補が2つ以上ならアカウント選択は必要
|
|
|
|
|
else -> null
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 簡易投稿入力のテキスト
|
|
|
|
|
val quickTootText : String
|
|
|
|
|
get() = etQuickToot.text.toString()
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// アクティビティイベント
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState : Bundle?) {
|
|
|
|
|
log.d("onCreate")
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
2019-10-07 21:39:56 +02:00
|
|
|
|
App1.setActivityTheme(this, noActionBar = true)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
handler = Handler()
|
|
|
|
|
app_state = App1.getAppState(this)
|
|
|
|
|
pref = App1.pref
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
density = app_state.density
|
|
|
|
|
acct_pad_lr = (0.5f + 4f * density).toInt()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
timeline_font_size_sp = Pref.fpTimelineFontSize(pref).clipFontSize()
|
|
|
|
|
acct_font_size_sp = Pref.fpAcctFontSize(pref).clipFontSize()
|
|
|
|
|
notification_tl_font_size_sp = Pref.fpNotificationTlFontSize(pref).clipFontSize()
|
|
|
|
|
header_text_size_sp = Pref.fpHeaderTextSize(pref).clipFontSize()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-12-15 16:34:46 +01:00
|
|
|
|
val fv = Pref.spTimelineSpacing(pref).toFloatOrNull()
|
|
|
|
|
timeline_spacing = if(fv != null && fv.isFinite() && fv != 0f) fv else null
|
2019-10-22 20:56:24 +02:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
initUI()
|
|
|
|
|
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
2019-08-07 02:53:53 +02:00
|
|
|
|
if(app_state.column_list.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// 前回最後に表示していたカラムの位置にスクロールする
|
2018-01-17 02:16:26 +01:00
|
|
|
|
val column_pos = Pref.ipLastColumnPos(pref)
|
2019-10-10 22:59:47 +02:00
|
|
|
|
log.d("ipLastColumnPos load $column_pos")
|
|
|
|
|
if(column_pos in 0 until app_state.column_list.size) {
|
2018-01-19 10:27:35 +01:00
|
|
|
|
scrollToColumn(column_pos, false)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 表示位置に合わせたイベントを発行
|
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> onPageSelected(env.pager.currentItem) },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PollingWorker.queueUpdateNotification(this)
|
|
|
|
|
|
|
|
|
|
if(savedInstanceState != null) {
|
|
|
|
|
sent_intent2?.let { handleSentIntent(it) }
|
|
|
|
|
}
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
|
|
|
|
checkPrivacyPolicy()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
|
log.d("onDestroy")
|
|
|
|
|
super.onDestroy()
|
|
|
|
|
post_helper.onDestroy()
|
|
|
|
|
|
|
|
|
|
// このアクティビティに関連する ColumnViewHolder への参照を全カラムから除去する
|
|
|
|
|
for(c in app_state.column_list) {
|
|
|
|
|
c.removeColumnViewHolderByActivity(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 19:19:21 +01:00
|
|
|
|
override fun onNewIntent(intent : Intent?) {
|
|
|
|
|
super.onNewIntent(intent)
|
|
|
|
|
log.w("onNewIntent: isResumed = isResumed")
|
|
|
|
|
}
|
2018-11-19 23:46:14 +01:00
|
|
|
|
|
2019-11-14 07:37:45 +01:00
|
|
|
|
override fun onConfigurationChanged(newConfig : Configuration) {
|
|
|
|
|
log.d("onConfigurationChanged")
|
|
|
|
|
super.onConfigurationChanged(newConfig)
|
2019-12-15 16:34:46 +01:00
|
|
|
|
if(newConfig.screenHeightDp > 0 || newConfig.screenHeightDp > 0) {
|
2019-11-14 07:37:45 +01:00
|
|
|
|
tabOnly { env -> resizeColumnWidth(env) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 15:43:11 +02:00
|
|
|
|
override fun onSaveInstanceState(outState : Bundle) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onSaveInstanceState(outState)
|
2019-09-12 15:43:11 +02:00
|
|
|
|
|
|
|
|
|
log.d("onSaveInstanceState")
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
|
|
|
|
phoneTab(
|
2018-01-17 02:16:26 +01:00
|
|
|
|
{ env -> outState.putInt(STATE_CURRENT_PAGE, env.pager.currentItem) },
|
2018-01-10 16:47:35 +01:00
|
|
|
|
{ env ->
|
2020-01-10 14:42:37 +01:00
|
|
|
|
env.tablet_layout_manager.findLastVisibleItemPosition()
|
|
|
|
|
.takeIf { it != RecyclerView.NO_POSITION }
|
|
|
|
|
?.let { outState.putInt(STATE_CURRENT_PAGE, it) }
|
|
|
|
|
}
|
|
|
|
|
)
|
2018-08-18 12:58:14 +02:00
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
|
for(column in app_state.column_list) {
|
2018-08-24 15:45:27 +02:00
|
|
|
|
column.saveScrollPosition()
|
2018-08-18 12:58:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onRestoreInstanceState(savedInstanceState : Bundle) {
|
|
|
|
|
log.d("onRestoreInstanceState")
|
|
|
|
|
super.onRestoreInstanceState(savedInstanceState)
|
|
|
|
|
val pos = savedInstanceState.getInt(STATE_CURRENT_PAGE)
|
|
|
|
|
if(pos > 0 && pos < app_state.column_list.size) {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.currentItem = pos },
|
2018-01-17 02:16:26 +01:00
|
|
|
|
{ env ->
|
|
|
|
|
env.tablet_layout_manager
|
|
|
|
|
.smoothScrollToPosition(env.tablet_pager, null, pos)
|
|
|
|
|
}
|
2018-01-10 16:47:35 +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
|
|
|
|
override fun onStart() {
|
2019-10-05 14:28:04 +02:00
|
|
|
|
val tsTotal = SystemClock.elapsedRealtime()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onStart()
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
isStart_ = true
|
2018-01-04 19:52:25 +01:00
|
|
|
|
log.d("onStart")
|
|
|
|
|
|
2019-10-06 13:23:33 +02:00
|
|
|
|
var ts = SystemClock.elapsedRealtime()
|
|
|
|
|
var te : Long
|
2019-10-05 14:28:04 +02:00
|
|
|
|
|
2018-08-15 12:22:19 +02:00
|
|
|
|
// カラーカスタマイズを読み直す
|
|
|
|
|
ListDivider.color = Pref.ipListDividerColor(pref)
|
2018-11-24 08:04:42 +01:00
|
|
|
|
TabletColumnDivider.color = Pref.ipListDividerColor(pref)
|
2018-08-24 07:04:55 +02:00
|
|
|
|
ItemViewHolder.toot_color_unlisted = Pref.ipTootColorUnlisted(pref)
|
|
|
|
|
ItemViewHolder.toot_color_follower = Pref.ipTootColorFollower(pref)
|
|
|
|
|
ItemViewHolder.toot_color_direct_user = Pref.ipTootColorDirectUser(pref)
|
|
|
|
|
ItemViewHolder.toot_color_direct_me = Pref.ipTootColorDirectMe(pref)
|
2019-01-25 15:38:21 +01:00
|
|
|
|
MyClickableSpan.showLinkUnderline = Pref.bpShowLinkUnderline(pref)
|
|
|
|
|
MyClickableSpan.defaultLinkColor = Pref.ipLinkColor(pref).notZero()
|
|
|
|
|
?: getAttributeColor(this, R.attr.colorLink)
|
2019-08-07 02:53:53 +02:00
|
|
|
|
CustomShare.reloadCache(this, pref)
|
2019-03-13 18:34:56 +01:00
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms : reload color")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
|
2019-01-30 17:20:49 +01:00
|
|
|
|
var tz = TimeZone.getDefault()
|
2019-02-03 15:12:03 +01:00
|
|
|
|
try {
|
2019-01-30 17:20:49 +01:00
|
|
|
|
val tz_id = Pref.spTimeZone(pref)
|
2019-02-03 15:12:03 +01:00
|
|
|
|
if(tz_id.isNotEmpty()) {
|
2019-01-30 17:20:49 +01:00
|
|
|
|
tz = TimeZone.getTimeZone(tz_id)
|
|
|
|
|
}
|
2019-02-03 15:12:03 +01:00
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.e(ex, "getTimeZone failed.")
|
2019-01-30 17:20:49 +01:00
|
|
|
|
}
|
|
|
|
|
TootStatus.date_format.timeZone = tz
|
2019-08-25 10:28:16 +02:00
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms : reload timezone")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
|
2019-08-25 10:04:34 +02:00
|
|
|
|
// バグいアカウントデータを消す
|
2019-08-25 10:28:16 +02:00
|
|
|
|
try {
|
2019-08-25 10:04:34 +02:00
|
|
|
|
SavedAccount.sweepBuggieData()
|
2019-08-25 10:28:16 +02:00
|
|
|
|
} catch(ex : Throwable) {
|
2019-08-25 10:04:34 +02:00
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
2019-01-30 17:20:49 +01:00
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms : sweepBuggieData")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// アカウント設定から戻ってきたら、カラムを消す必要があるかもしれない
|
2019-08-25 10:04:34 +02:00
|
|
|
|
val new_order = ArrayList<Int>()
|
|
|
|
|
|
|
|
|
|
for(i in 0 until app_state.column_list.size) {
|
|
|
|
|
val column = app_state.column_list[i]
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-08-25 10:04:34 +02:00
|
|
|
|
if(! column.access_info.isNA) {
|
|
|
|
|
// 存在確認
|
|
|
|
|
SavedAccount.loadAccount(this@ActMain, column.access_info.db_id)
|
|
|
|
|
?: continue
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2019-08-25 10:04:34 +02:00
|
|
|
|
new_order.add(i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(new_order.size != app_state.column_list.size) {
|
|
|
|
|
setOrder(new_order)
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms : column order")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2019-08-25 10:04:34 +02:00
|
|
|
|
// 背景画像を表示しない設定が変更された時にカラムの背景を設定しなおす
|
|
|
|
|
for(column in app_state.column_list) {
|
2020-01-27 16:41:18 +01:00
|
|
|
|
column.viewHolder?.lastAnnouncementShown = 0L
|
2019-08-25 10:04:34 +02:00
|
|
|
|
column.fireColumnColor()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :fireColumnColor")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 各カラムのアカウント設定を読み直す
|
|
|
|
|
reloadAccountSetting()
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :reloadAccountSetting")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 投稿直後ならカラムの再取得を行う
|
|
|
|
|
refreshAfterPost()
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :refreshAfterPost")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 画面復帰時に再取得やストリーミング開始を行う
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.onStart(this)
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :column.onStart")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// カラムの表示範囲インジケータを更新
|
|
|
|
|
updateColumnStripSelection(- 1, - 1f)
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :updateColumnStripSelection")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
ts = SystemClock.elapsedRealtime()
|
|
|
|
|
|
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
|
for(c in app_state.column_list) {
|
2018-01-21 13:46:36 +01:00
|
|
|
|
c.fireShowContent(reason = "ActMain onStart", reset = true)
|
2018-01-20 07:51:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - ts >= 100L) log.w("onStart: ${te - ts}ms :fireShowContent")
|
2019-10-05 14:28:04 +02:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 相対時刻表示
|
|
|
|
|
proc_updateRelativeTime.run()
|
|
|
|
|
|
2019-10-05 14:28:04 +02:00
|
|
|
|
|
|
|
|
|
te = SystemClock.elapsedRealtime()
|
2019-10-06 13:23:33 +02:00
|
|
|
|
if(te - tsTotal >= 100L) log.w("onStart: ${te - tsTotal}ms : total")
|
2020-01-06 00:41:08 +01:00
|
|
|
|
|
|
|
|
|
app_state.enableSpeech()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
|
|
|
|
|
|
log.d("onStop")
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
isStart_ = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
handler.removeCallbacks(proc_updateRelativeTime)
|
|
|
|
|
|
|
|
|
|
post_helper.closeAcctPopup()
|
|
|
|
|
|
|
|
|
|
closeListItemPopup()
|
|
|
|
|
|
|
|
|
|
app_state.stream_reader.stopAll()
|
|
|
|
|
|
2018-08-24 15:45:27 +02:00
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.saveScrollPosition()
|
|
|
|
|
}
|
|
|
|
|
app_state.saveColumnList(bEnableSpeech = false)
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onStop()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
|
log.d("onResume")
|
2018-11-12 19:19:21 +01:00
|
|
|
|
isResumed = true
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-01-10 14:42:37 +01:00
|
|
|
|
super.onResume()
|
|
|
|
|
/*
|
|
|
|
|
super.onResume() から呼ばれる isTopOfTask() が android.os.RemoteException 例外をたまに出すが、放置することにした。
|
|
|
|
|
|
|
|
|
|
java.lang.RuntimeException:
|
|
|
|
|
at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4430)
|
|
|
|
|
at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4470)
|
|
|
|
|
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:183)
|
|
|
|
|
at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:165)
|
|
|
|
|
at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:142)
|
|
|
|
|
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:70)
|
|
|
|
|
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2199)
|
|
|
|
|
at android.os.Handler.dispatchMessage (Handler.java:112)
|
|
|
|
|
at android.os.Looper.loop (Looper.java:216)
|
|
|
|
|
at android.app.ActivityThread.main (ActivityThread.java:7625)
|
|
|
|
|
at java.lang.reflect.Method.invoke (Native Method)
|
|
|
|
|
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
|
|
|
|
|
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
|
|
|
|
|
Caused by: java.lang.IllegalArgumentException:
|
|
|
|
|
at android.os.Parcel.createException (Parcel.java:1957)
|
|
|
|
|
at android.os.Parcel.readException (Parcel.java:1921)
|
|
|
|
|
at android.os.Parcel.readException (Parcel.java:1871)
|
|
|
|
|
at android.app.IActivityManager$Stub$Proxy.isTopOfTask (IActivityManager.java:7912)
|
|
|
|
|
at android.app.Activity.isTopOfTask (Activity.java:6724)
|
|
|
|
|
at android.app.Activity.onResume (Activity.java:1425)
|
|
|
|
|
at androidx.fragment.app.FragmentActivity.onResume (FragmentActivity.java:456)
|
|
|
|
|
at jp.juggler.subwaytooter.ActMain.onResume (ActMain.kt:685)
|
|
|
|
|
at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1456)
|
|
|
|
|
at android.app.Activity.performResume (Activity.java:7614)
|
|
|
|
|
at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4412)
|
|
|
|
|
Caused by: android.os.RemoteException:
|
|
|
|
|
at com.android.server.am.ActivityManagerService.isTopOfTask (ActivityManagerService.java:16128)
|
|
|
|
|
at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:2376)
|
|
|
|
|
at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:3648)
|
|
|
|
|
at com.android.server.am.HwActivityManagerService.onTransact (HwActivityManagerService.java:609)
|
|
|
|
|
at android.os.Binder.execTransact (Binder.java:739)
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
MyClickableSpan.link_callback = WeakReference(link_click_listener)
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
if(Pref.bpDontScreenOff(pref)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
|
|
|
} else {
|
|
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 外部から受け取ったUriの処理
|
|
|
|
|
val uri = ActCallback.last_uri.getAndSet(null)
|
|
|
|
|
if(uri != null) {
|
|
|
|
|
handleIntentUri(uri)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 外部から受け取ったUriの処理
|
|
|
|
|
val intent = ActCallback.sent_intent.getAndSet(null)
|
|
|
|
|
if(intent != null) {
|
|
|
|
|
handleSentIntent(intent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
|
log.d("onPause")
|
2018-11-12 19:19:21 +01:00
|
|
|
|
isResumed = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// 最後に表示していたカラムの位置
|
2018-01-10 16:47:35 +01:00
|
|
|
|
val last_pos = phoneTab(
|
|
|
|
|
{ env -> env.pager.currentItem },
|
2019-10-10 22:59:47 +02:00
|
|
|
|
{ env -> env.visibleColumnsIndices.first })
|
|
|
|
|
log.d("ipLastColumnPos save $last_pos")
|
2018-09-17 20:06:15 +02:00
|
|
|
|
pref.edit().put(Pref.ipLastColumnPos, last_pos).apply()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-08-24 15:45:27 +02:00
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.saveScrollPosition()
|
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-08-24 15:45:27 +02:00
|
|
|
|
app_state.saveColumnList(bEnableSpeech = false)
|
2018-08-18 12:58:14 +02:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onPause()
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// UIイベント
|
|
|
|
|
|
|
|
|
|
override fun onPageScrollStateChanged(state : Int) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onPageScrolled(
|
|
|
|
|
position : Int,
|
|
|
|
|
positionOffset : Float,
|
|
|
|
|
positionOffsetPixels : Int
|
|
|
|
|
) {
|
|
|
|
|
updateColumnStripSelection(position, positionOffset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onPageSelected(position : Int) {
|
|
|
|
|
handler.post {
|
|
|
|
|
if(position >= 0 && position < app_state.column_list.size) {
|
|
|
|
|
val column = app_state.column_list[position]
|
|
|
|
|
if(! column.bFirstInitialized) {
|
|
|
|
|
column.startLoading()
|
|
|
|
|
}
|
|
|
|
|
scrollColumnStrip(position)
|
2020-05-16 16:59:18 +02:00
|
|
|
|
post_helper.setInstance(
|
|
|
|
|
when {
|
|
|
|
|
column.access_info.isNA -> null
|
|
|
|
|
else -> column.access_info
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-10-09 17:09:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onClick(v : View) {
|
|
|
|
|
when(v.id) {
|
|
|
|
|
R.id.btnMenu -> if(! drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
|
drawer.openDrawer(GravityCompat.START)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
R.id.btnToot -> Action_Account.openPost(this@ActMain)
|
|
|
|
|
|
|
|
|
|
R.id.btnQuickToot -> performQuickPost(null)
|
|
|
|
|
|
|
|
|
|
R.id.btnQuickTootMenu -> performQuickTootMenu()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// スマホモードとタブレットモードでコードを切り替える
|
|
|
|
|
private inline fun <R> phoneTab(
|
|
|
|
|
codePhone : (PhoneEnv) -> R,
|
|
|
|
|
codeTablet : (TabletEnv) -> R
|
|
|
|
|
) : R {
|
|
|
|
|
|
|
|
|
|
val pe = phoneEnv
|
|
|
|
|
if(pe != null) return codePhone(pe)
|
|
|
|
|
|
|
|
|
|
val te = tabletEnv
|
|
|
|
|
if(te != null) return codeTablet(te)
|
|
|
|
|
|
|
|
|
|
throw RuntimeException("missing phoneEnv or tabletEnv")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// スマホモードならラムダを実行する。タブレットモードならnullを返す
|
|
|
|
|
private inline fun <R> phoneOnly(code : (PhoneEnv) -> R) : R? {
|
|
|
|
|
val pe = phoneEnv
|
|
|
|
|
return if(pe != null) code(pe) else null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// タブレットモードならラムダを実行する。スマホモードならnullを返す
|
|
|
|
|
@Suppress("unused")
|
|
|
|
|
private inline fun <R> tabOnly(code : (TabletEnv) -> R) : R? {
|
|
|
|
|
val te = tabletEnv
|
|
|
|
|
return if(te != null) code(te) else null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新しいカラムをどこに挿入するか
|
|
|
|
|
// カラムの次の位置か、現在のページの次の位置か、終端
|
|
|
|
|
fun nextPosition(column : Column?) : Int {
|
|
|
|
|
if(column != null) {
|
|
|
|
|
val pos = app_state.column_list.indexOf(column)
|
|
|
|
|
if(pos != - 1) return pos + 1
|
|
|
|
|
}
|
|
|
|
|
return defaultInsertPosition
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
private fun refreshAfterPost() {
|
2018-02-08 05:14:46 +01:00
|
|
|
|
val posted_acct = this.posted_acct
|
2018-08-18 12:58:14 +02:00
|
|
|
|
val posted_status_id = this.posted_status_id
|
2019-01-06 11:17:54 +01:00
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(posted_acct != null && posted_status_id == null) {
|
2019-01-06 11:17:54 +01:00
|
|
|
|
// 予約投稿なら予約投稿リストをリロードする
|
|
|
|
|
for(column in app_state.column_list) {
|
2019-08-23 01:49:20 +02:00
|
|
|
|
if(column.type == ColumnType.SCHEDULED_STATUS
|
2020-02-02 15:19:57 +01:00
|
|
|
|
&& column.access_info.acct == posted_acct
|
2019-08-07 02:53:53 +02:00
|
|
|
|
) {
|
2019-01-06 11:17:54 +01:00
|
|
|
|
column.startLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
|
} else if(posted_acct != null && posted_status_id != null) {
|
2018-06-23 04:43:18 +02:00
|
|
|
|
|
2018-08-18 12:58:14 +02:00
|
|
|
|
val posted_redraft_id = this.posted_redraft_id
|
2018-08-21 12:19:02 +02:00
|
|
|
|
if(posted_redraft_id != null) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
val host = posted_acct.host
|
|
|
|
|
if(host != null) {
|
2018-06-23 04:43:18 +02:00
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.onStatusRemoved(host, posted_redraft_id)
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-18 12:58:14 +02:00
|
|
|
|
this.posted_redraft_id = null
|
2018-06-23 04:43:18 +02:00
|
|
|
|
}
|
2018-07-05 14:38:48 +02:00
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
val refresh_after_toot = Pref.ipRefreshAfterToot(pref)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(refresh_after_toot != Pref.RAT_DONT_REFRESH) {
|
|
|
|
|
for(column in app_state.column_list) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(column.access_info.acct != posted_acct) continue
|
2018-02-08 05:14:46 +01:00
|
|
|
|
column.startRefreshForPost(
|
|
|
|
|
refresh_after_toot,
|
|
|
|
|
posted_status_id,
|
|
|
|
|
posted_reply_id
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-08 05:14:46 +01:00
|
|
|
|
this.posted_acct = null
|
2018-08-18 12:58:14 +02:00
|
|
|
|
this.posted_status_id = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun handleSentIntent(intent : Intent) {
|
|
|
|
|
sent_intent2 = intent
|
2018-11-19 23:46:14 +01:00
|
|
|
|
|
2018-11-12 19:19:21 +01:00
|
|
|
|
// Galaxy S8+ で STのSSを取った後に出るポップアップからそのまま共有でSTを選ぶと何も起きない問題への対策
|
2018-11-19 23:46:14 +01:00
|
|
|
|
handler.post {
|
2018-11-12 19:19:21 +01:00
|
|
|
|
AccountPicker.pick(
|
|
|
|
|
this,
|
|
|
|
|
bAllowPseudo = false,
|
|
|
|
|
bAuto = true,
|
|
|
|
|
message = getString(R.string.account_picker_toot)
|
|
|
|
|
, dismiss_callback = { sent_intent2 = null }
|
|
|
|
|
) { ai ->
|
|
|
|
|
sent_intent2 = null
|
|
|
|
|
ActPost.open(this@ActMain, REQUEST_CODE_POST, ai.db_id, sent_intent = intent)
|
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun closeListItemPopup() {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
try {
|
|
|
|
|
listItemPopup?.dismiss()
|
|
|
|
|
} catch(ignored : Throwable) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
listItemPopup = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 22:19:15 +02:00
|
|
|
|
private fun performQuickTootMenu() {
|
|
|
|
|
dlgQuickTootMenu.toggle()
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
private fun performQuickPost(account : SavedAccount?) {
|
|
|
|
|
if(account == null) {
|
2019-10-09 17:21:58 +02:00
|
|
|
|
val a = if(tabletEnv != null && ! Pref.bpQuickTootOmitAccountSelection(pref)) {
|
|
|
|
|
// タブレットモードでオプションが無効なら
|
|
|
|
|
// 簡易投稿は常にアカウント選択する
|
|
|
|
|
null
|
|
|
|
|
} else {
|
|
|
|
|
currentPostTarget
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
if(a != null && ! a.isPseudo) {
|
|
|
|
|
performQuickPost(a)
|
|
|
|
|
} else {
|
|
|
|
|
// アカウントを選択してやり直し
|
2018-01-13 07:15:52 +01:00
|
|
|
|
AccountPicker.pick(
|
|
|
|
|
this,
|
|
|
|
|
bAllowPseudo = false,
|
2018-01-17 02:16:26 +01:00
|
|
|
|
bAuto = true,
|
|
|
|
|
message = getString(R.string.account_picker_toot)
|
2018-01-13 07:15:52 +01:00
|
|
|
|
) { ai -> performQuickPost(ai) }
|
2019-10-09 17:09:52 +02:00
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
post_helper.content = etQuickToot.text.toString().trim { it <= ' ' }
|
|
|
|
|
post_helper.spoiler_text = null
|
2019-06-04 01:24:54 +02:00
|
|
|
|
|
|
|
|
|
post_helper.visibility = when(quickTootVisibility) {
|
|
|
|
|
TootVisibility.AccountSetting -> account.visibility
|
|
|
|
|
else -> quickTootVisibility
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
post_helper.bNSFW = false
|
2018-08-18 12:58:14 +02:00
|
|
|
|
post_helper.in_reply_to_id = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
post_helper.attachment_list = null
|
2018-11-12 18:19:57 +01:00
|
|
|
|
post_helper.emojiMapCustom =
|
2020-05-16 16:59:18 +02:00
|
|
|
|
App1.custom_emoji_lister.getMap(account)
|
2018-03-10 17:22:13 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
|
etQuickToot.hideKeyboard()
|
2018-01-21 17:47:13 +01:00
|
|
|
|
|
2019-01-28 19:02:09 +01:00
|
|
|
|
post_helper.post(account, callback = object : PostHelper.PostCompleteCallback {
|
2019-01-06 09:20:37 +01:00
|
|
|
|
override fun onPostComplete(
|
|
|
|
|
target_account : SavedAccount,
|
|
|
|
|
status : TootStatus
|
|
|
|
|
) {
|
|
|
|
|
etQuickToot.setText("")
|
2020-02-02 15:19:57 +01:00
|
|
|
|
posted_acct = target_account.acct
|
2019-01-06 09:20:37 +01:00
|
|
|
|
posted_status_id = status.id
|
|
|
|
|
posted_reply_id = status.in_reply_to_id
|
|
|
|
|
posted_redraft_id = null
|
|
|
|
|
refreshAfterPost()
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 19:06:56 +01:00
|
|
|
|
override fun onScheduledPostComplete(target_account : SavedAccount) {
|
2019-01-06 09:20:37 +01:00
|
|
|
|
}
|
|
|
|
|
})
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun isOrderChanged(new_order : ArrayList<Int>) : Boolean {
|
|
|
|
|
if(new_order.size != app_state.column_list.size) return true
|
|
|
|
|
var i = 0
|
|
|
|
|
val ie = new_order.size
|
|
|
|
|
while(i < ie) {
|
|
|
|
|
if(new_order[i] != i) return true
|
|
|
|
|
++ i
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode : Int, resultCode : Int, data : Intent?) {
|
2018-11-20 01:15:05 +01:00
|
|
|
|
log.d("onActivityResult req=$requestCode res=$resultCode data=$data")
|
2018-11-19 23:46:14 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(resultCode == Activity.RESULT_OK) {
|
2018-11-20 01:15:05 +01:00
|
|
|
|
when(requestCode) {
|
|
|
|
|
REQUEST_CODE_COLUMN_LIST -> if(data != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val order = data.getIntegerArrayListExtra(ActColumnList.EXTRA_ORDER)
|
|
|
|
|
if(order != null && isOrderChanged(order)) {
|
|
|
|
|
setOrder(order)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 02:53:53 +02:00
|
|
|
|
if(app_state.column_list.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val select = data.getIntExtra(ActColumnList.EXTRA_SELECTION, - 1)
|
|
|
|
|
if(0 <= select && select < app_state.column_list.size) {
|
2018-01-19 10:27:35 +01:00
|
|
|
|
scrollToColumn(select)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_APP_ABOUT -> if(data != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val search = data.getStringExtra(ActAbout.EXTRA_SEARCH)
|
2018-01-10 16:47:35 +01:00
|
|
|
|
if(search?.isNotEmpty() == true) {
|
2018-01-18 19:09:36 +01:00
|
|
|
|
Action_Account.timeline(
|
2018-11-20 01:15:05 +01:00
|
|
|
|
this@ActMain,
|
|
|
|
|
defaultInsertPosition,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
ColumnType.SEARCH,
|
2018-11-20 01:15:05 +01:00
|
|
|
|
args = arrayOf(search, true)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_NICKNAME -> {
|
|
|
|
|
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.fireShowColumnHeader()
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_POST -> if(data != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
etQuickToot.setText("")
|
2020-02-02 15:19:57 +01:00
|
|
|
|
posted_acct =
|
|
|
|
|
data.getStringExtra(ActPost.EXTRA_POSTED_ACCT)?.let { Acct.parse(it) }
|
2019-01-28 19:02:09 +01:00
|
|
|
|
if(data.extras?.containsKey(ActPost.EXTRA_POSTED_STATUS_ID) == true) {
|
2019-01-06 11:17:54 +01:00
|
|
|
|
posted_status_id = EntityId.from(data, ActPost.EXTRA_POSTED_STATUS_ID)
|
|
|
|
|
posted_reply_id = EntityId.from(data, ActPost.EXTRA_POSTED_REPLY_ID)
|
|
|
|
|
posted_redraft_id = EntityId.from(data, ActPost.EXTRA_POSTED_REDRAFT_ID)
|
2019-01-28 19:02:09 +01:00
|
|
|
|
} else {
|
2019-01-06 15:55:25 +01:00
|
|
|
|
posted_status_id = null
|
2019-01-06 11:17:54 +01:00
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-11-30 11:54:32 +01:00
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_COLUMN_COLOR -> if(data != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
val idx = data.getIntExtra(ActColumnCustomize.EXTRA_COLUMN_INDEX, 0)
|
2019-12-15 16:34:46 +01:00
|
|
|
|
if(idx in app_state.column_list.indices) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
app_state.column_list[idx].fireColumnColor()
|
2018-01-21 13:46:36 +01:00
|
|
|
|
app_state.column_list[idx].fireShowContent(
|
|
|
|
|
reason = "ActMain column color changed",
|
|
|
|
|
reset = true
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
}
|
2019-12-15 16:34:46 +01:00
|
|
|
|
|
2019-12-13 15:48:38 +01:00
|
|
|
|
REQUEST_CODE_LANGUAGE_FILTER -> if(data != null) {
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
val idx = data.getIntExtra(ActLanguageFilter.EXTRA_COLUMN_INDEX, 0)
|
2019-12-15 16:34:46 +01:00
|
|
|
|
if(idx in app_state.column_list.indices) {
|
2019-12-13 15:48:38 +01:00
|
|
|
|
app_state.column_list[idx].onLanguageFilterChanged()
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
when(requestCode) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_ACCOUNT_SETTING -> {
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
column.fireShowColumnHeader()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(resultCode == Activity.RESULT_OK && data != null) {
|
|
|
|
|
startAccessTokenUpdate(data)
|
|
|
|
|
} else if(resultCode == ActAccountSetting.RESULT_INPUT_ACCESS_TOKEN && data != null) {
|
|
|
|
|
val db_id = data.getLongExtra(ActAccountSetting.EXTRA_DB_ID, - 1L)
|
|
|
|
|
checkAccessToken2(db_id)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_APP_SETTING -> {
|
|
|
|
|
Column.reloadDefaultColor(this, pref)
|
|
|
|
|
showFooterColor()
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
if(resultCode == RESULT_APP_DATA_IMPORT) {
|
|
|
|
|
importAppData(data?.data)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
REQUEST_CODE_TEXT -> when(resultCode) {
|
|
|
|
|
ActText.RESULT_SEARCH_MSP -> {
|
|
|
|
|
val text = data?.getStringExtra(Intent.EXTRA_TEXT) ?: ""
|
|
|
|
|
addColumn(
|
|
|
|
|
false,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
SavedAccount.na,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
ColumnType.SEARCH_MSP,
|
2018-11-20 01:15:05 +01:00
|
|
|
|
text
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActText.RESULT_SEARCH_TS -> {
|
|
|
|
|
val text = data?.getStringExtra(Intent.EXTRA_TEXT) ?: ""
|
|
|
|
|
addColumn(
|
|
|
|
|
false,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
SavedAccount.na,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
ColumnType.SEARCH_TS,
|
2018-11-20 01:15:05 +01:00
|
|
|
|
text
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
|
|
|
|
|
|
// メニューが開いていたら閉じる
|
|
|
|
|
if(drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// カラムが0個ならアプリを終了する
|
|
|
|
|
if(app_state.column_list.isEmpty()) {
|
|
|
|
|
this@ActMain.finish()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// カラム設定が開いているならカラム設定を閉じる
|
|
|
|
|
if(closeColumnSetting()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
fun getClosableColumnList() : List<Column> {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
val visibleColumnList = ArrayList<Column>()
|
|
|
|
|
phoneTab({ env ->
|
2018-09-20 18:41:04 +02:00
|
|
|
|
try {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
visibleColumnList.add(app_state.column_list[env.pager.currentItem])
|
2018-09-20 18:41:04 +02:00
|
|
|
|
} catch(ex : Throwable) {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
}
|
|
|
|
|
}, { env ->
|
2019-10-09 17:21:58 +02:00
|
|
|
|
visibleColumnList.addAll(env.visibleColumns)
|
2018-09-17 20:06:15 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
return visibleColumnList.filter { ! it.dont_close }
|
2018-09-17 20:06:15 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// カラムが1個以上ある場合は設定に合わせて挙動を変える
|
2018-01-18 19:09:36 +01:00
|
|
|
|
when(Pref.ipBackButtonAction(pref)) {
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-12-03 09:07:07 +01:00
|
|
|
|
Pref.BACK_EXIT_APP -> this@ActMain.finish()
|
2018-09-17 20:06:15 +02:00
|
|
|
|
|
2018-12-03 09:07:07 +01:00
|
|
|
|
Pref.BACK_OPEN_COLUMN_LIST -> Action_App.columnList(this@ActMain)
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-12-03 09:07:07 +01:00
|
|
|
|
Pref.BACK_CLOSE_COLUMN -> {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-09-17 20:06:15 +02:00
|
|
|
|
val closeableColumnList = getClosableColumnList()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
when(closeableColumnList.size) {
|
|
|
|
|
0 -> {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
if(Pref.bpExitAppWhenCloseProtectedColumn(pref)
|
|
|
|
|
&& Pref.bpDontConfirmBeforeCloseColumn(pref)
|
2018-09-20 18:41:04 +02:00
|
|
|
|
) {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
this@ActMain.finish()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
} else {
|
|
|
|
|
showToast(this@ActMain, false, R.string.missing_closeable_column)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
|
|
|
|
1 -> {
|
|
|
|
|
closeColumn(closeableColumnList.first())
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
|
showToast(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
false,
|
|
|
|
|
R.string.cant_close_column_by_back_button_when_multiple_column_shown
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 20:06:15 +02:00
|
|
|
|
// ActAppSetting.BACK_ASK_ALWAYS
|
2018-01-04 19:52:25 +01:00
|
|
|
|
else -> {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
|
|
|
|
|
val closeableColumnList = getClosableColumnList()
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val dialog = ActionsDialog()
|
2018-09-17 20:06:15 +02:00
|
|
|
|
|
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
if(closeableColumnList.size == 1) {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
val column = closeableColumnList.first()
|
|
|
|
|
dialog.addAction(getString(R.string.close_column)) {
|
2018-09-20 18:41:04 +02:00
|
|
|
|
closeColumn(column, bConfirmed = true)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
dialog.addAction(getString(R.string.open_column_list)) { Action_App.columnList(this@ActMain) }
|
|
|
|
|
dialog.addAction(getString(R.string.app_exit)) { this@ActMain.finish() }
|
|
|
|
|
dialog.show(this, null)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal fun initUI() {
|
|
|
|
|
setContentView(R.layout.act_main)
|
2019-08-31 16:33:13 +02:00
|
|
|
|
App1.initEdgeToEdge(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
|
quickTootVisibility =
|
|
|
|
|
TootVisibility.parseSavedVisibility(Pref.spQuickTootVisibility(pref))
|
|
|
|
|
?: quickTootVisibility
|
2018-09-07 14:38:01 +02:00
|
|
|
|
|
2018-11-20 01:15:05 +01:00
|
|
|
|
Column.reloadDefaultColor(this, pref)
|
2018-11-19 23:46:14 +01:00
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
var sv = Pref.spTimelineFont(pref)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
if(sv.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
timeline_font = Typeface.createFromFile(sv)
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
sv = Pref.spTimelineFontBold(pref)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
if(sv.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
timeline_font_bold = Typeface.createFromFile(sv)
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 03:05:54 +02:00
|
|
|
|
} else {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
timeline_font_bold = Typeface.create(timeline_font, Typeface.BOLD)
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 19:26:24 +02:00
|
|
|
|
fun parseIconSize(stringPref : StringPref) : Int {
|
2018-06-24 03:12:45 +02:00
|
|
|
|
var icon_size_dp = stringPref.defVal.toFloat()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
2018-06-24 03:12:45 +02:00
|
|
|
|
sv = stringPref(pref)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
val fv = if(sv.isEmpty()) Float.NaN else sv.toFloat()
|
|
|
|
|
if(fv.isFinite() && fv >= 1f) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
icon_size_dp = fv
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
2018-06-24 03:12:45 +02:00
|
|
|
|
return (0.5f + icon_size_dp * density).toInt()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-24 03:12:45 +02:00
|
|
|
|
avatarIconSize = parseIconSize(Pref.spAvatarIconSize)
|
|
|
|
|
notificationTlIconSize = parseIconSize(Pref.spNotificationTlIconSize)
|
2018-08-21 15:31:44 +02:00
|
|
|
|
boostButtonSize = parseIconSize(Pref.spBoostButtonSize)
|
2019-01-08 03:02:02 +01:00
|
|
|
|
replyIconSize = parseIconSize(Pref.spReplyIconSize)
|
2019-01-11 10:47:30 +01:00
|
|
|
|
headerIconSize = parseIconSize(Pref.spHeaderIconSize)
|
2019-01-15 14:43:56 +01:00
|
|
|
|
stripIconSize = parseIconSize(Pref.spStripIconSize)
|
2018-01-18 08:53:32 +01:00
|
|
|
|
run {
|
|
|
|
|
var round_ratio = 33f
|
|
|
|
|
try {
|
2018-01-18 19:09:36 +01:00
|
|
|
|
if(Pref.bpDontRound(pref)) {
|
2018-01-18 08:53:32 +01:00
|
|
|
|
round_ratio = 0f
|
2018-01-18 19:09:36 +01:00
|
|
|
|
} else {
|
2018-01-18 08:53:32 +01:00
|
|
|
|
sv = Pref.spRoundRatio(pref)
|
|
|
|
|
if(sv.isNotEmpty()) {
|
|
|
|
|
val fv = sv.toFloat()
|
|
|
|
|
if(fv.isFinite()) {
|
|
|
|
|
round_ratio = fv
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
2018-01-18 19:09:36 +01:00
|
|
|
|
Styler.round_ratio = clipRange(0f, 1f, round_ratio / 100f) * 0.5f
|
2018-01-18 08:53:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-18 15:29:35 +01:00
|
|
|
|
run {
|
2019-01-17 20:40:51 +01:00
|
|
|
|
var boost_alpha = 0.8f
|
2018-11-19 23:46:14 +01:00
|
|
|
|
try {
|
|
|
|
|
val f = (Pref.spBoostAlpha.toInt(pref).toFloat() + 0.5f) / 100f
|
|
|
|
|
boost_alpha = when {
|
2019-01-17 20:40:51 +01:00
|
|
|
|
f >= 1f -> 1f
|
2018-11-18 15:29:35 +01:00
|
|
|
|
f < 0f -> 0.66f
|
2018-11-19 23:46:14 +01:00
|
|
|
|
else -> f
|
2018-11-18 15:29:35 +01:00
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
Styler.boost_alpha = boost_alpha
|
|
|
|
|
}
|
2018-01-18 08:53:32 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
llEmpty = findViewById(R.id.llEmpty)
|
|
|
|
|
|
|
|
|
|
drawer = findViewById(R.id.drawer_layout)
|
2018-01-17 02:16:26 +01:00
|
|
|
|
drawer.addDrawerListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
drawer.setExclusionSize(stripIconSize)
|
2020-02-05 09:18:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
SideMenuAdapter(this, findViewById(R.id.nav_view), drawer)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
btnMenu = findViewById(R.id.btnMenu)
|
|
|
|
|
btnToot = findViewById(R.id.btnToot)
|
|
|
|
|
vFooterDivider1 = findViewById(R.id.vFooterDivider1)
|
|
|
|
|
vFooterDivider2 = findViewById(R.id.vFooterDivider2)
|
|
|
|
|
llColumnStrip = findViewById(R.id.llColumnStrip)
|
|
|
|
|
svColumnStrip = findViewById(R.id.svColumnStrip)
|
|
|
|
|
llQuickTootBar = findViewById(R.id.llQuickTootBar)
|
|
|
|
|
etQuickToot = findViewById(R.id.etQuickToot)
|
|
|
|
|
btnQuickToot = findViewById(R.id.btnQuickToot)
|
2019-04-12 22:19:15 +02:00
|
|
|
|
btnQuickTootMenu = findViewById(R.id.btnQuickTootMenu)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
|
|
|
|
|
|
when(Pref.ipJustifyWindowContentPortrait(pref)) {
|
|
|
|
|
Pref.JWCP_START -> {
|
2019-12-16 10:34:53 +01:00
|
|
|
|
val iconW = (stripIconSize * 1.5f + 0.5f).toInt()
|
2020-01-10 14:42:37 +01:00
|
|
|
|
val padding = resources.displayMetrics.widthPixels / 2 - iconW
|
2019-12-15 20:12:57 +01:00
|
|
|
|
|
2020-01-10 14:42:37 +01:00
|
|
|
|
fun ViewGroup.addViewBeforeLast(v : View) = addView(v, childCount - 1)
|
2019-12-15 20:12:57 +01:00
|
|
|
|
(svColumnStrip.parent as LinearLayout).addViewBeforeLast(
|
|
|
|
|
View(this).apply {
|
|
|
|
|
layoutParams = LinearLayout.LayoutParams(padding, 0)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
llQuickTootBar.addViewBeforeLast(
|
|
|
|
|
View(this).apply {
|
|
|
|
|
layoutParams = LinearLayout.LayoutParams(padding, 0)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pref.JWCP_END -> {
|
2019-12-16 10:34:53 +01:00
|
|
|
|
val iconW = (stripIconSize * 1.5f + 0.5f).toInt()
|
|
|
|
|
val borderWidth = (1f * density + 0.5f).toInt()
|
2020-01-10 14:42:37 +01:00
|
|
|
|
val padding = resources.displayMetrics.widthPixels / 2 - iconW - borderWidth
|
2019-12-15 20:12:57 +01:00
|
|
|
|
|
|
|
|
|
fun ViewGroup.addViewAfterFirst(v : View) = addView(v, 1)
|
|
|
|
|
(svColumnStrip.parent as LinearLayout).addViewAfterFirst(
|
|
|
|
|
View(this).apply {
|
|
|
|
|
layoutParams = LinearLayout.LayoutParams(padding, 0)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
llQuickTootBar.addViewAfterFirst(
|
|
|
|
|
View(this).apply {
|
|
|
|
|
layoutParams = LinearLayout.LayoutParams(padding, 0)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
if(! Pref.bpQuickTootBar(pref)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
llQuickTootBar.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
btnToot.setOnClickListener(this)
|
|
|
|
|
btnMenu.setOnClickListener(this)
|
|
|
|
|
btnQuickToot.setOnClickListener(this)
|
2019-04-12 22:19:15 +02:00
|
|
|
|
btnQuickTootMenu.setOnClickListener(this)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
if(Pref.bpDontUseActionButtonWithQuickTootBar(pref)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
etQuickToot.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
|
|
|
|
etQuickToot.imeOptions = EditorInfo.IME_ACTION_NONE
|
|
|
|
|
// 最後に指定する必要がある?
|
|
|
|
|
etQuickToot.maxLines = 5
|
|
|
|
|
etQuickToot.isVerticalScrollBarEnabled = true
|
|
|
|
|
etQuickToot.isScrollbarFadingEnabled = false
|
|
|
|
|
} else {
|
|
|
|
|
etQuickToot.inputType = InputType.TYPE_CLASS_TEXT
|
|
|
|
|
etQuickToot.imeOptions = EditorInfo.IME_ACTION_SEND
|
|
|
|
|
etQuickToot.setOnEditorActionListener(TextView.OnEditorActionListener { _, actionId, _ ->
|
|
|
|
|
if(actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
|
btnQuickToot.performClick()
|
|
|
|
|
return@OnEditorActionListener true
|
|
|
|
|
}
|
|
|
|
|
false
|
|
|
|
|
})
|
|
|
|
|
// 最後に指定する必要がある?
|
|
|
|
|
etQuickToot.maxLines = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svColumnStrip.isHorizontalFadingEdgeEnabled = true
|
|
|
|
|
|
|
|
|
|
post_helper = PostHelper(this, pref, app_state.handler)
|
|
|
|
|
|
|
|
|
|
val dm = resources.displayMetrics
|
|
|
|
|
|
|
|
|
|
val density = dm.density
|
|
|
|
|
|
|
|
|
|
var media_thumb_height = 64
|
2018-01-17 02:16:26 +01:00
|
|
|
|
sv = Pref.spMediaThumbHeight(pref)
|
2018-01-17 18:39:16 +01:00
|
|
|
|
if(sv.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
val iv = Integer.parseInt(sv)
|
|
|
|
|
if(iv >= 32) {
|
|
|
|
|
media_thumb_height = iv
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
app_state.media_thumb_height = (0.5f + media_thumb_height * density).toInt()
|
|
|
|
|
|
|
|
|
|
var column_w_min_dp = COLUMN_WIDTH_MIN_DP
|
2018-01-17 02:16:26 +01:00
|
|
|
|
sv = Pref.spColumnWidth(pref)
|
|
|
|
|
if(sv.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
val iv = Integer.parseInt(sv)
|
|
|
|
|
if(iv >= 100) {
|
|
|
|
|
column_w_min_dp = iv
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
val column_w_min = (0.5f + column_w_min_dp * density).toInt()
|
|
|
|
|
|
|
|
|
|
val sw = dm.widthPixels
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
if(Pref.bpDisableTabletMode(pref) || sw < column_w_min * 2) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// SmartPhone mode
|
|
|
|
|
findViewById<View>(R.id.rvPager).visibility = View.GONE
|
|
|
|
|
phoneEnv = PhoneEnv()
|
|
|
|
|
} else {
|
|
|
|
|
// Tablet mode
|
|
|
|
|
findViewById<View>(R.id.viewPager).visibility = View.GONE
|
|
|
|
|
tabletEnv = TabletEnv()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
phoneTab({ env ->
|
|
|
|
|
env.pager = findViewById(R.id.viewPager)
|
|
|
|
|
env.pager_adapter = ColumnPagerAdapter(this)
|
|
|
|
|
env.pager.adapter = env.pager_adapter
|
|
|
|
|
env.pager.addOnPageChangeListener(this)
|
|
|
|
|
|
|
|
|
|
resizeAutoCW(sw)
|
|
|
|
|
|
|
|
|
|
}, { env ->
|
|
|
|
|
env.tablet_pager = findViewById(R.id.rvPager)
|
|
|
|
|
env.tablet_pager_adapter = TabletColumnPagerAdapter(this)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
env.tablet_layout_manager =
|
2019-03-13 19:08:28 +01:00
|
|
|
|
LinearLayoutManager(
|
2019-02-15 02:51:22 +01:00
|
|
|
|
this,
|
2019-03-13 19:08:28 +01:00
|
|
|
|
LinearLayoutManager.HORIZONTAL,
|
2019-02-15 02:51:22 +01:00
|
|
|
|
false
|
|
|
|
|
)
|
2018-11-24 08:04:42 +01:00
|
|
|
|
|
|
|
|
|
if(env.tablet_pager.itemDecorationCount == 0) {
|
|
|
|
|
env.tablet_pager.addItemDecoration(TabletColumnDivider(this@ActMain))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
env.tablet_pager.adapter = env.tablet_pager_adapter
|
|
|
|
|
env.tablet_pager.layoutManager = env.tablet_layout_manager
|
2019-03-13 18:34:56 +01:00
|
|
|
|
env.tablet_pager.addOnScrollListener(object :
|
2019-03-13 19:08:28 +01:00
|
|
|
|
RecyclerView.OnScrollListener() {
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
override fun onScrollStateChanged(
|
2019-03-13 19:08:28 +01:00
|
|
|
|
recyclerView : RecyclerView,
|
2019-03-13 18:34:56 +01:00
|
|
|
|
newState : Int
|
|
|
|
|
) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onScrollStateChanged(recyclerView, newState)
|
2018-09-17 20:06:15 +02:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val vs = env.tablet_layout_manager.findFirstVisibleItemPosition()
|
|
|
|
|
val ve = env.tablet_layout_manager.findLastVisibleItemPosition()
|
|
|
|
|
// 端に近い方に合わせる
|
2019-08-07 02:53:53 +02:00
|
|
|
|
val distance_left = abs(vs)
|
|
|
|
|
val distance_right = abs(app_state.column_list.size - 1 - ve)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(distance_left < distance_right) {
|
|
|
|
|
scrollColumnStrip(vs)
|
|
|
|
|
} else {
|
|
|
|
|
scrollColumnStrip(ve)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
override fun onScrolled(
|
2019-03-13 19:08:28 +01:00
|
|
|
|
recyclerView : RecyclerView,
|
2019-03-13 18:34:56 +01:00
|
|
|
|
dx : Int,
|
|
|
|
|
dy : Int
|
|
|
|
|
) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
super.onScrolled(recyclerView, dx, dy)
|
|
|
|
|
updateColumnStripSelection(- 1, - 1f)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
|
env.tablet_pager.itemAnimator = null
|
2018-01-21 13:46:36 +01:00
|
|
|
|
// val animator = env.tablet_pager.itemAnimator
|
|
|
|
|
// if( animator is DefaultItemAnimator){
|
|
|
|
|
// animator.supportsChangeAnimations = false
|
|
|
|
|
// }
|
2018-01-20 07:51:14 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
env.tablet_snap_helper = GravitySnapHelper(Gravity.START)
|
|
|
|
|
env.tablet_snap_helper.attachToRecyclerView(env.tablet_pager)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
showFooterColor()
|
|
|
|
|
|
2018-01-18 19:09:36 +01:00
|
|
|
|
post_helper.attachEditText(
|
|
|
|
|
findViewById(R.id.llFormRoot),
|
|
|
|
|
etQuickToot,
|
|
|
|
|
true,
|
|
|
|
|
object : PostHelper.Callback2 {
|
|
|
|
|
override fun onTextUpdate() {}
|
|
|
|
|
|
|
|
|
|
override fun canOpenPopup() : Boolean {
|
2019-03-13 19:06:56 +01:00
|
|
|
|
return ! drawer.isDrawerOpen(GravityCompat.START)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
}
|
|
|
|
|
})
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:09:52 +02:00
|
|
|
|
private fun isVisibleColumn(idx : Int) = phoneTab(
|
|
|
|
|
{ env ->
|
|
|
|
|
val c = env.pager.currentItem
|
|
|
|
|
c == idx
|
|
|
|
|
}, { env ->
|
|
|
|
|
idx >= 0 && idx in env.visibleColumnsIndices
|
|
|
|
|
}
|
|
|
|
|
)
|
2018-07-10 08:44:34 +02:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
private fun updateColumnStrip() {
|
2019-12-15 16:34:46 +01:00
|
|
|
|
llEmpty.vg(app_state.column_list.isEmpty())
|
2019-01-15 14:43:56 +01:00
|
|
|
|
|
|
|
|
|
val iconSize = stripIconSize
|
|
|
|
|
val rootW = (iconSize * 1.25f + 0.5f).toInt()
|
|
|
|
|
val rootH = (iconSize * 1.5f + 0.5f).toInt()
|
|
|
|
|
val iconTopMargin = (iconSize * 0.125f + 0.5f).toInt()
|
|
|
|
|
val barHeight = (iconSize * 0.094f + 0.5f).toInt()
|
|
|
|
|
val barTopMargin = (iconSize * 0.094f + 0.5f).toInt()
|
|
|
|
|
|
|
|
|
|
// 両端のメニューと投稿ボタンの大きさ
|
2019-01-28 19:02:09 +01:00
|
|
|
|
val pad = (rootH - iconSize) shr 1
|
2020-01-10 14:42:37 +01:00
|
|
|
|
for(btn in arrayOf(btnToot, btnMenu, btnQuickTootMenu, btnQuickToot)) {
|
2019-12-15 20:12:57 +01:00
|
|
|
|
btn.layoutParams.width = rootH // not W
|
|
|
|
|
btn.layoutParams.height = rootH
|
|
|
|
|
btn.setPaddingRelative(pad, pad, pad, pad)
|
|
|
|
|
}
|
2020-01-10 14:42:37 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
llColumnStrip.removeAllViews()
|
2018-01-17 02:16:26 +01:00
|
|
|
|
for(i in 0 until app_state.column_list.size) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
val column = app_state.column_list[i]
|
|
|
|
|
|
|
|
|
|
val viewRoot = layoutInflater.inflate(R.layout.lv_column_strip, llColumnStrip, false)
|
|
|
|
|
val ivIcon = viewRoot.findViewById<ImageView>(R.id.ivIcon)
|
2019-01-15 14:43:56 +01:00
|
|
|
|
val vAcctColor = viewRoot.findViewById<View>(R.id.vAcctColor)
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
2019-01-15 14:43:56 +01:00
|
|
|
|
// root: 48x48dp LinearLayout(vertical), gravity=center
|
|
|
|
|
viewRoot.layoutParams.width = rootW
|
|
|
|
|
viewRoot.layoutParams.height = rootH
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
2019-01-15 14:43:56 +01:00
|
|
|
|
// ivIcon: 32x32dp marginTop="4dp" 図柄が32x32dp、パディングなし
|
|
|
|
|
ivIcon.layoutParams.width = iconSize
|
|
|
|
|
ivIcon.layoutParams.height = iconSize
|
|
|
|
|
(ivIcon.layoutParams as? LinearLayout.LayoutParams)?.topMargin = iconTopMargin
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
2019-01-15 14:43:56 +01:00
|
|
|
|
// vAcctColor: 32x3dp marginTop="3dp"
|
|
|
|
|
vAcctColor.layoutParams.width = iconSize
|
|
|
|
|
vAcctColor.layoutParams.height = barHeight
|
|
|
|
|
(vAcctColor.layoutParams as? LinearLayout.LayoutParams)?.topMargin = barTopMargin
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
viewRoot.tag = i
|
2018-07-10 08:44:34 +02:00
|
|
|
|
viewRoot.setOnClickListener { v ->
|
|
|
|
|
val idx = v.tag as Int
|
|
|
|
|
if(Pref.bpScrollTopFromColumnStrip(pref) && isVisibleColumn(idx)) {
|
|
|
|
|
app_state.column_list[i].viewHolder?.scrollToTop2()
|
|
|
|
|
return@setOnClickListener
|
|
|
|
|
}
|
|
|
|
|
scrollToColumn(idx)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
viewRoot.contentDescription = column.getColumnName(true)
|
2020-04-07 06:52:54 +02:00
|
|
|
|
|
2020-02-11 18:01:15 +01:00
|
|
|
|
viewRoot.backgroundDrawable = getAdaptiveRippleDrawableRound(
|
|
|
|
|
this,
|
|
|
|
|
column.getHeaderBackgroundColor(),
|
|
|
|
|
column.getHeaderNameColor()
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-08-23 01:49:20 +02:00
|
|
|
|
ivIcon.setImageResource(column.getIconId())
|
2019-01-17 20:40:51 +01:00
|
|
|
|
ivIcon.imageTintList = ColorStateList.valueOf(column.getHeaderNameColor())
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
//
|
2020-02-02 07:25:08 +01:00
|
|
|
|
val ac = AcctColor.load(column.access_info)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(AcctColor.hasColorForeground(ac)) {
|
|
|
|
|
vAcctColor.setBackgroundColor(ac.color_fg)
|
2019-01-28 19:02:09 +01:00
|
|
|
|
} else {
|
2019-01-15 14:43:56 +01:00
|
|
|
|
vAcctColor.visibility = View.INVISIBLE
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
//
|
|
|
|
|
llColumnStrip.addView(viewRoot)
|
|
|
|
|
}
|
|
|
|
|
svColumnStrip.requestLayout()
|
|
|
|
|
updateColumnStripSelection(- 1, - 1f)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateColumnStripSelection(position : Int, positionOffset : Float) {
|
|
|
|
|
handler.post(Runnable {
|
|
|
|
|
if(isFinishing) return@Runnable
|
|
|
|
|
|
|
|
|
|
if(app_state.column_list.isEmpty()) {
|
2018-01-13 16:24:51 +01:00
|
|
|
|
llColumnStrip.setVisibleRange(- 1, - 1, 0f)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
} else {
|
|
|
|
|
phoneTab({ env ->
|
|
|
|
|
if(position >= 0) {
|
2018-01-13 16:24:51 +01:00
|
|
|
|
llColumnStrip.setVisibleRange(position, position, positionOffset)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
} else {
|
|
|
|
|
val c = env.pager.currentItem
|
2018-01-13 16:24:51 +01:00
|
|
|
|
llColumnStrip.setVisibleRange(c, c, 0f)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, { env ->
|
2019-10-09 17:09:52 +02:00
|
|
|
|
val vs = env.tablet_layout_manager.findFirstVisibleItemPosition()
|
|
|
|
|
val ve = env.tablet_layout_manager.findLastVisibleItemPosition()
|
|
|
|
|
val vr = if(vs == RecyclerView.NO_POSITION || ve == RecyclerView.NO_POSITION) {
|
|
|
|
|
IntRange(- 1, - 2) // empty and less than zero
|
2019-10-09 17:21:58 +02:00
|
|
|
|
} else {
|
2019-10-09 17:09:52 +02:00
|
|
|
|
IntRange(vs, min(ve, vs + nScreenColumn - 1))
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
var slide_ratio = 0f
|
2018-09-20 18:41:04 +02:00
|
|
|
|
if(vr.first <= vr.last) {
|
2018-09-17 20:06:15 +02:00
|
|
|
|
val child = env.tablet_layout_manager.findViewByPosition(vr.first)
|
2018-11-30 11:54:32 +01:00
|
|
|
|
slide_ratio =
|
|
|
|
|
clipRange(0f, 1f, abs((child?.left ?: 0) / nColumnWidth.toFloat()))
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 20:06:15 +02:00
|
|
|
|
llColumnStrip.setVisibleRange(vr.first, vr.last, slide_ratio)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun scrollColumnStrip(select : Int) {
|
|
|
|
|
val child_count = llColumnStrip.childCount
|
|
|
|
|
if(select < 0 || select >= child_count) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val icon = llColumnStrip.getChildAt(select)
|
|
|
|
|
|
|
|
|
|
val sv_width = (llColumnStrip.parent as View).width
|
|
|
|
|
val ll_width = llColumnStrip.width
|
|
|
|
|
val icon_width = icon.width
|
|
|
|
|
val icon_left = icon.left
|
|
|
|
|
|
|
|
|
|
if(sv_width == 0 || ll_width == 0 || icon_width == 0) {
|
|
|
|
|
handler.postDelayed({ scrollColumnStrip(select) }, 20L)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val sx = icon_left + icon_width / 2 - sv_width / 2
|
|
|
|
|
svColumnStrip.smoothScrollTo(sx, 0)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun startAccessTokenUpdate(data : Intent) {
|
2019-01-28 19:02:09 +01:00
|
|
|
|
App1.openBrowser(this, data.data)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ActOAuthCallbackで受け取ったUriを処理する
|
|
|
|
|
private fun handleIntentUri(uri : Uri) {
|
2018-11-12 18:19:57 +01:00
|
|
|
|
|
2018-11-02 01:09:31 +01:00
|
|
|
|
log.d("handleIntentUri ${uri}")
|
2018-11-12 18:19:57 +01:00
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
|
when(uri.scheme) {
|
|
|
|
|
"subwaytooter", "misskeyclientproto" -> return try {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
handleOAuth2CallbackUri(uri)
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val url = uri.toString()
|
|
|
|
|
|
2019-09-30 13:02:39 +02:00
|
|
|
|
val statusInfo = url.findStatusIdFromUrl()
|
2019-10-02 11:37:41 +02:00
|
|
|
|
if(statusInfo != null) {
|
2019-09-30 13:02:39 +02:00
|
|
|
|
// ステータスをアプリ内で開く
|
|
|
|
|
Action_Toot.conversationOtherInstance(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
statusInfo.url,
|
|
|
|
|
statusInfo.statusId,
|
|
|
|
|
statusInfo.host,
|
|
|
|
|
statusInfo.statusId
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
// ユーザページをアプリ内で開く
|
2019-09-30 13:02:39 +02:00
|
|
|
|
var m = TootAccount.reAccountUrl.matcher(url)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(m.find()) {
|
2019-09-12 16:05:18 +02:00
|
|
|
|
val host = m.groupEx(1) !!
|
|
|
|
|
val user = m.groupEx(2) !!.decodePercent()
|
|
|
|
|
val instance = m.groupEx(3)?.decodePercent()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
|
|
|
|
if(instance?.isNotEmpty() == true) {
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
null,
|
|
|
|
|
"https://$instance/@$user",
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(instance),
|
2019-02-13 08:17:49 +01:00
|
|
|
|
user,
|
|
|
|
|
original_url = url
|
2018-09-20 18:41:04 +02:00
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
null,
|
|
|
|
|
url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(host),
|
2018-09-20 18:41:04 +02:00
|
|
|
|
user
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 19:02:09 +01:00
|
|
|
|
// intentFilterの都合でこの形式のURLが飛んでくることはないのだが…。
|
|
|
|
|
m = TootAccount.reAccountUrl2.matcher(url)
|
|
|
|
|
if(m.find()) {
|
2019-09-12 16:05:18 +02:00
|
|
|
|
val host = m.groupEx(1) !!
|
|
|
|
|
val user = m.groupEx(2) !!.decodePercent()
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
null,
|
|
|
|
|
url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(host),
|
2019-01-28 19:02:09 +01:00
|
|
|
|
user
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// このアプリでは処理できないURLだった
|
|
|
|
|
// 外部ブラウザを開きなおそうとすると無限ループの恐れがある
|
|
|
|
|
// アプリケーションチューザーを表示する
|
|
|
|
|
|
|
|
|
|
val error_message = getString(R.string.cant_handle_uri_of, url)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
val query_flag = if(Build.VERSION.SDK_INT >= 23) {
|
|
|
|
|
// Android 6.0以降
|
|
|
|
|
// MATCH_DEFAULT_ONLY だと標準の設定に指定されたアプリがあるとソレしか出てこない
|
|
|
|
|
// MATCH_ALL を指定すると 以前と同じ挙動になる
|
|
|
|
|
PackageManager.MATCH_ALL
|
|
|
|
|
} else {
|
|
|
|
|
// Android 5.xまでは MATCH_DEFAULT_ONLY でマッチするすべてのアプリを取得できる
|
|
|
|
|
PackageManager.MATCH_DEFAULT_ONLY
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// queryIntentActivities に渡すURLは実在しないホストのものにする
|
2018-11-30 11:54:32 +01:00
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW, "https://dummy.subwaytooter.club/".toUri())
|
2018-01-04 19:52:25 +01:00
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
|
val resolveInfoList = packageManager.queryIntentActivities(intent, query_flag)
|
|
|
|
|
if(resolveInfoList.isEmpty()) {
|
|
|
|
|
throw RuntimeException("resolveInfoList is empty.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// このアプリ以外の選択肢を集める
|
|
|
|
|
val my_name = packageName
|
|
|
|
|
val choice_list = ArrayList<Intent>()
|
|
|
|
|
for(ri in resolveInfoList) {
|
|
|
|
|
|
|
|
|
|
// 選択肢からこのアプリを除外
|
|
|
|
|
if(my_name == ri.activityInfo.packageName) continue
|
|
|
|
|
|
|
|
|
|
// 選択肢のIntentは目的のUriで作成する
|
|
|
|
|
val choice = Intent(Intent.ACTION_VIEW, uri)
|
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
|
choice.`package` = ri.activityInfo.packageName
|
|
|
|
|
choice.setClassName(ri.activityInfo.packageName, ri.activityInfo.name)
|
|
|
|
|
choice_list.add(choice)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(choice_list.isEmpty()) {
|
|
|
|
|
throw RuntimeException("choice_list is empty.")
|
|
|
|
|
}
|
|
|
|
|
// 指定した選択肢でチューザーを作成して開く
|
|
|
|
|
val chooser = Intent.createChooser(choice_list.removeAt(0), error_message)
|
|
|
|
|
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, choice_list.toTypedArray())
|
|
|
|
|
startActivity(chooser)
|
|
|
|
|
return
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
|
.setCancelable(true)
|
|
|
|
|
.setMessage(error_message)
|
|
|
|
|
.setPositiveButton(R.string.close, null)
|
|
|
|
|
.show()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun handleOAuth2CallbackUri(uri : Uri) {
|
|
|
|
|
|
|
|
|
|
// 通知タップ
|
|
|
|
|
// subwaytooter://notification_click/?db_id=(db_id)
|
|
|
|
|
val dataIdString = uri.getQueryParameter("db_id")
|
2018-01-10 16:47:35 +01:00
|
|
|
|
if(dataIdString != null) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
|
2020-01-16 10:31:14 +01:00
|
|
|
|
PollingWorker.queueNotificationClicked(this, uri)
|
2020-02-02 15:19:57 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
2020-01-16 10:31:14 +01:00
|
|
|
|
val dataId = dataIdString.toLong()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val account = SavedAccount.loadAccount(this@ActMain, dataId)
|
|
|
|
|
if(account != null) {
|
2018-02-06 21:41:30 +01:00
|
|
|
|
var column = app_state.column_list.firstOrNull {
|
2019-08-23 01:49:20 +02:00
|
|
|
|
it.type == ColumnType.NOTIFICATIONS
|
2020-02-02 07:25:08 +01:00
|
|
|
|
&& account == it.access_info
|
2018-02-06 21:41:30 +01:00
|
|
|
|
&& ! it.system_notification_not_related
|
|
|
|
|
}
|
2018-02-08 05:14:46 +01:00
|
|
|
|
if(column != null) {
|
2018-02-06 21:41:30 +01:00
|
|
|
|
val index = app_state.column_list.indexOf(column)
|
|
|
|
|
scrollToColumn(index)
|
2018-02-08 05:14:46 +01:00
|
|
|
|
} else {
|
2018-02-06 21:41:30 +01:00
|
|
|
|
column = addColumn(
|
|
|
|
|
true,
|
|
|
|
|
defaultInsertPosition,
|
|
|
|
|
account,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
ColumnType.NOTIFICATIONS
|
2018-02-06 21:41:30 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 通知を読み直す
|
|
|
|
|
if(! column.bInitialLoading) {
|
|
|
|
|
column.startLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OAuth2 認証コールバック
|
2019-03-13 18:34:56 +01:00
|
|
|
|
// subwaytooter://oauth(\d*)/?...
|
2018-01-10 16:47:35 +01:00
|
|
|
|
TootTaskRunner(this@ActMain).run(object : TootTask {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-07-05 14:38:48 +02:00
|
|
|
|
var ta : TootAccount? = null
|
|
|
|
|
var sa : SavedAccount? = null
|
2020-02-02 15:19:57 +01:00
|
|
|
|
var host : Host? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
|
|
|
|
|
2018-08-19 06:19:33 +02:00
|
|
|
|
val uriStr = uri.toString()
|
2018-08-21 12:19:02 +02:00
|
|
|
|
if(uriStr.startsWith("subwaytooter://misskey/auth_callback")
|
2018-08-19 06:19:33 +02:00
|
|
|
|
|| uriStr.startsWith("misskeyclientproto://misskeyclientproto/auth_callback")
|
2018-08-21 12:19:02 +02:00
|
|
|
|
) {
|
2018-08-19 06:19:33 +02:00
|
|
|
|
|
|
|
|
|
// Misskey 認証コールバック
|
|
|
|
|
val token = uri.getQueryParameter("token")
|
|
|
|
|
if(token?.isEmpty() != false) {
|
|
|
|
|
return TootApiResult("missing token in callback URL")
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-08-19 06:19:33 +02:00
|
|
|
|
val prefDevice = PrefDevice.prefDevice(this@ActMain)
|
2018-08-21 12:19:02 +02:00
|
|
|
|
|
|
|
|
|
val db_id = prefDevice.getLong(PrefDevice.LAST_AUTH_DB_ID, - 1L)
|
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
|
val instance = Host.parse(
|
|
|
|
|
prefDevice.getString(PrefDevice.LAST_AUTH_INSTANCE, null)
|
|
|
|
|
?: return TootApiResult("missing instance name.")
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
|
if(db_id != - 1L) {
|
2018-08-19 06:19:33 +02:00
|
|
|
|
try {
|
|
|
|
|
val sa = SavedAccount.loadAccount(this@ActMain, db_id)
|
|
|
|
|
?: return TootApiResult("missing account db_id=$db_id")
|
|
|
|
|
this.sa = sa
|
|
|
|
|
client.account = sa
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
return TootApiResult(ex.withCaption("invalid state"))
|
|
|
|
|
}
|
2018-08-21 12:19:02 +02:00
|
|
|
|
} else {
|
2018-08-19 06:19:33 +02:00
|
|
|
|
client.instance = instance
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-06 13:23:33 +02:00
|
|
|
|
val (ti, r2) = TootInstance.get(client)
|
|
|
|
|
ti ?: return r2
|
2019-04-25 04:06:41 +02:00
|
|
|
|
|
2018-08-19 06:19:33 +02:00
|
|
|
|
this.host = instance
|
|
|
|
|
val client_name = Pref.spClientName(this@ActMain)
|
2019-10-02 11:37:41 +02:00
|
|
|
|
val result =
|
|
|
|
|
client.authentication2Misskey(client_name, token, ti.misskeyVersion)
|
2018-08-19 06:19:33 +02:00
|
|
|
|
this.ta = TootParser(
|
2018-08-20 02:07:55 +02:00
|
|
|
|
this@ActMain
|
2019-10-02 11:37:41 +02:00
|
|
|
|
, LinkHelper.newLinkHelper(instance, misskeyVersion = ti.misskeyVersion)
|
2018-08-19 06:19:33 +02:00
|
|
|
|
).account(result?.jsonObject)
|
|
|
|
|
return result
|
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
|
} else {
|
2018-08-19 06:19:33 +02:00
|
|
|
|
// Mastodon 認証コールバック
|
|
|
|
|
|
|
|
|
|
// エラー時
|
2019-03-13 18:34:56 +01:00
|
|
|
|
// subwaytooter://oauth(\d*)/
|
2018-08-19 06:19:33 +02:00
|
|
|
|
// ?error=access_denied
|
|
|
|
|
// &error_description=%E3%83%AA%E3%82%BD%E3%83%BC%E3%82%B9%E3%81%AE%E6%89%80%E6%9C%89%E8%80%85%E3%81%BE%E3%81%9F%E3%81%AF%E8%AA%8D%E8%A8%BC%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%81%8C%E8%A6%81%E6%B1%82%E3%82%92%E6%8B%92%E5%90%A6%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82
|
|
|
|
|
// &state=db%3A3
|
|
|
|
|
val error = uri.getQueryParameter("error_description")
|
|
|
|
|
if(error?.isNotEmpty() == true) {
|
|
|
|
|
return TootApiResult(error)
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
// subwaytooter://oauth(\d*)/
|
2018-08-19 06:19:33 +02:00
|
|
|
|
// ?code=113cc036e078ac500d3d0d3ad345cd8181456ab087abc67270d40f40a4e9e3c2
|
|
|
|
|
// &state=host%3Amastodon.juggler.jp
|
|
|
|
|
|
|
|
|
|
val code = uri.getQueryParameter("code")
|
|
|
|
|
if(code?.isEmpty() != false) {
|
|
|
|
|
return TootApiResult("missing code in callback url.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val sv = uri.getQueryParameter("state")
|
|
|
|
|
if(sv?.isEmpty() != false) {
|
|
|
|
|
return TootApiResult("missing state in callback url.")
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 19:08:28 +01:00
|
|
|
|
for(param in sv.split(",")) {
|
2019-03-13 18:34:56 +01:00
|
|
|
|
when {
|
2019-03-13 19:08:28 +01:00
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
param.startsWith("db:") -> try {
|
|
|
|
|
val dataId = param.substring(3).toLong(10)
|
|
|
|
|
val sa = SavedAccount.loadAccount(this@ActMain, dataId)
|
|
|
|
|
?: return TootApiResult("missing account db_id=$dataId")
|
|
|
|
|
this.sa = sa
|
|
|
|
|
client.account = sa
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
return TootApiResult(ex.withCaption("invalid state"))
|
|
|
|
|
}
|
2019-03-13 19:08:28 +01:00
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
param.startsWith("host:") -> {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
val host = Host.parse(param.substring(5))
|
2019-03-13 18:34:56 +01:00
|
|
|
|
client.instance = host
|
|
|
|
|
}
|
2019-03-13 19:08:28 +01:00
|
|
|
|
|
2019-03-13 18:34:56 +01:00
|
|
|
|
else -> {
|
|
|
|
|
// ignore other parameter
|
|
|
|
|
}
|
2018-08-19 06:19:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val instance = client.instance
|
2019-03-13 18:34:56 +01:00
|
|
|
|
?: return TootApiResult("missing instance in callback url.")
|
2018-08-19 06:19:33 +02:00
|
|
|
|
|
|
|
|
|
this.host = instance
|
|
|
|
|
val client_name = Pref.spClientName(this@ActMain)
|
|
|
|
|
val result = client.authentication2(client_name, code)
|
2018-08-20 02:07:55 +02:00
|
|
|
|
this.ta = TootParser(
|
|
|
|
|
this@ActMain
|
|
|
|
|
, LinkHelper.newLinkHelper(instance)
|
|
|
|
|
).account(result?.jsonObject)
|
2018-08-19 06:19:33 +02:00
|
|
|
|
return result
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
2018-02-10 01:36:27 +01:00
|
|
|
|
val host = this.host
|
|
|
|
|
val ta = this.ta
|
|
|
|
|
var sa = this.sa
|
2018-03-10 17:22:13 +01:00
|
|
|
|
|
2020-02-05 09:18:28 +01:00
|
|
|
|
if(ta != null && host?.isValid == true && sa == null) {
|
|
|
|
|
val acct = Acct.parse(ta.username, host)
|
2018-02-10 01:36:27 +01:00
|
|
|
|
// アカウント追加時に、アプリ内に既にあるアカウントと同じものを登録していたかもしれない
|
2020-02-02 15:19:57 +01:00
|
|
|
|
sa = SavedAccount.loadAccountByAcct(this@ActMain, acct.ascii)
|
2018-02-10 01:36:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
afterAccountVerify(result, ta, sa, host)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 19:09:36 +01:00
|
|
|
|
internal fun afterAccountVerify(
|
|
|
|
|
result : TootApiResult?,
|
|
|
|
|
ta : TootAccount?,
|
|
|
|
|
sa : SavedAccount?,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
host : Host?
|
2018-01-18 19:09:36 +01:00
|
|
|
|
) : Boolean {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
val jsonObject = result?.jsonObject
|
2018-01-13 07:15:52 +01:00
|
|
|
|
val token_info = result?.tokenInfo
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val error = result?.error
|
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
when {
|
|
|
|
|
result == null -> {
|
|
|
|
|
// cancelled.
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-10-06 13:23:33 +02:00
|
|
|
|
error != null -> showToast(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
true,
|
|
|
|
|
"${result.error} ${result.requestInfo}".trim()
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
token_info == null -> showToast(this@ActMain, true, "can't get access token.")
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
jsonObject == null -> showToast(this@ActMain, true, "can't parse json response.")
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// 自分のユーザネームを取れなかった
|
|
|
|
|
// …普通はエラーメッセージが設定されてるはずだが
|
2019-08-25 10:28:16 +02:00
|
|
|
|
ta == null -> showToast(this@ActMain, true, "can't verify user credential.")
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// アクセストークン更新時
|
|
|
|
|
// インスタンスは同じだと思うが、ユーザ名が異なる可能性がある
|
2019-08-25 10:28:16 +02:00
|
|
|
|
sa != null ->
|
|
|
|
|
if(sa.username != ta.username) {
|
|
|
|
|
showToast(this@ActMain, true, R.string.user_name_not_match)
|
|
|
|
|
} else {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
showToast(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
false,
|
|
|
|
|
R.string.access_token_updated_for,
|
|
|
|
|
sa.acct.pretty
|
|
|
|
|
)
|
2019-08-25 10:28:16 +02:00
|
|
|
|
|
|
|
|
|
// DBの情報を更新する
|
|
|
|
|
sa.updateTokenInfo(token_info)
|
|
|
|
|
|
|
|
|
|
// 各カラムの持つアカウント情報をリロードする
|
|
|
|
|
reloadAccountSetting()
|
|
|
|
|
|
|
|
|
|
// 自動でリロードする
|
|
|
|
|
for(it in app_state.column_list) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(it.access_info == sa) {
|
2019-08-25 10:28:16 +02:00
|
|
|
|
it.startLoading()
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2019-08-25 10:28:16 +02:00
|
|
|
|
|
|
|
|
|
// 通知の更新が必要かもしれない
|
2019-12-17 19:11:19 +01:00
|
|
|
|
PushSubscriptionHelper.clearLastCheck(sa)
|
2019-08-25 10:28:16 +02:00
|
|
|
|
PollingWorker.queueUpdateNotification(this@ActMain)
|
|
|
|
|
return true
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-02-10 01:36:27 +01:00
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
host != null -> {
|
|
|
|
|
// アカウント追加時
|
2020-02-05 09:18:28 +01:00
|
|
|
|
val user = Acct.parse(ta.username, host)
|
2018-08-21 12:19:02 +02:00
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
val row_id = SavedAccount.insert(
|
2020-02-02 15:19:57 +01:00
|
|
|
|
host.ascii,
|
|
|
|
|
user.ascii,
|
2019-08-25 10:28:16 +02:00
|
|
|
|
jsonObject,
|
|
|
|
|
token_info,
|
2019-10-02 11:37:41 +02:00
|
|
|
|
misskeyVersion = TootInstance.parseMisskeyVersion(token_info)
|
2019-08-25 10:28:16 +02:00
|
|
|
|
)
|
|
|
|
|
val account = SavedAccount.loadAccount(this@ActMain, row_id)
|
|
|
|
|
if(account != null) {
|
|
|
|
|
var bModified = false
|
|
|
|
|
|
|
|
|
|
if(account.loginAccount?.locked == true) {
|
|
|
|
|
bModified = true
|
|
|
|
|
account.visibility = TootVisibility.PrivateFollowers
|
|
|
|
|
}
|
|
|
|
|
if(! account.isMisskey) {
|
|
|
|
|
val source = ta.source
|
|
|
|
|
if(source != null) {
|
|
|
|
|
val privacy = TootVisibility.parseMastodon(source.privacy)
|
|
|
|
|
if(privacy != null) {
|
|
|
|
|
bModified = true
|
|
|
|
|
account.visibility = privacy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX ta.source.sensitive パラメータを読んで「添付画像をデフォルトでNSFWにする」を実現する
|
|
|
|
|
// 現在、アカウント設定にはこの項目はない( 「NSFWな添付メディアを隠さない」はあるが全く別の効果)
|
2018-08-20 19:37:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
if(bModified) {
|
|
|
|
|
account.saveSetting()
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
2019-08-25 10:28:16 +02:00
|
|
|
|
showToast(this@ActMain, false, R.string.account_confirmed)
|
|
|
|
|
|
|
|
|
|
// 通知の更新が必要かもしれない
|
|
|
|
|
PollingWorker.queueUpdateNotification(this@ActMain)
|
|
|
|
|
|
|
|
|
|
// 適当にカラムを追加する
|
|
|
|
|
val count = SavedAccount.count
|
|
|
|
|
if(count > 1) {
|
|
|
|
|
addColumn(false, defaultInsertPosition, account, ColumnType.HOME)
|
|
|
|
|
} else {
|
|
|
|
|
addColumn(false, defaultInsertPosition, account, ColumnType.HOME)
|
|
|
|
|
addColumn(false, defaultInsertPosition, account, ColumnType.NOTIFICATIONS)
|
|
|
|
|
addColumn(false, defaultInsertPosition, account, ColumnType.LOCAL)
|
|
|
|
|
addColumn(false, defaultInsertPosition, account, ColumnType.FEDERATE)
|
2018-08-20 19:37:42 +02:00
|
|
|
|
}
|
2019-08-25 10:28:16 +02:00
|
|
|
|
|
|
|
|
|
return true
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// アクセストークンを手動で入力した場合
|
|
|
|
|
fun checkAccessToken(
|
2018-01-18 19:09:36 +01:00
|
|
|
|
dialog_host : Dialog?,
|
|
|
|
|
dialog_token : Dialog?,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
host : Host,
|
2018-01-18 19:09:36 +01:00
|
|
|
|
access_token : String,
|
|
|
|
|
sa : SavedAccount?
|
2018-01-04 19:52:25 +01:00
|
|
|
|
) {
|
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
TootTaskRunner(this@ActMain).run(host, object : TootTask {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-07-05 14:38:48 +02:00
|
|
|
|
var ta : TootAccount? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
override fun background(client : TootApiClient) : TootApiResult? {
|
2018-08-20 19:37:42 +02:00
|
|
|
|
|
2019-10-06 13:23:33 +02:00
|
|
|
|
val (instance, instanceResult) = TootInstance.get(client, host)
|
|
|
|
|
instance ?: return instanceResult
|
2019-10-02 11:37:41 +02:00
|
|
|
|
|
|
|
|
|
val misskeyVersion = instance.misskeyVersion
|
2019-04-25 04:06:41 +02:00
|
|
|
|
val linkHelper = LinkHelper.newLinkHelper(host, misskeyVersion = misskeyVersion)
|
|
|
|
|
val result = client.getUserCredential(access_token, misskeyVersion = misskeyVersion)
|
2018-08-20 02:07:55 +02:00
|
|
|
|
this.ta = TootParser(this@ActMain, linkHelper)
|
|
|
|
|
.account(result?.jsonObject)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun handleResult(result : TootApiResult?) {
|
|
|
|
|
if(afterAccountVerify(result, ta, sa, host)) {
|
2019-01-19 03:36:40 +01:00
|
|
|
|
dialog_host?.dismissSafe()
|
|
|
|
|
dialog_token?.dismissSafe()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// アクセストークンの手動入力(更新)
|
|
|
|
|
private fun checkAccessToken2(db_id : Long) {
|
|
|
|
|
|
|
|
|
|
val sa = SavedAccount.loadAccount(this, db_id) ?: return
|
|
|
|
|
|
2018-01-18 19:09:36 +01:00
|
|
|
|
DlgTextInput.show(
|
|
|
|
|
this,
|
2018-08-21 12:19:02 +02:00
|
|
|
|
getString(R.string.access_token_or_api_token),
|
2018-01-18 19:09:36 +01:00
|
|
|
|
null,
|
|
|
|
|
object : DlgTextInput.Callback {
|
|
|
|
|
override fun onOK(dialog : Dialog, text : String) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
checkAccessToken(null, dialog, sa.host, text, sa)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onEmptyError() {
|
2018-01-21 13:46:36 +01:00
|
|
|
|
showToast(this@ActMain, true, R.string.token_not_specified)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
}
|
|
|
|
|
})
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun reloadAccountSetting() {
|
|
|
|
|
val done_list = ArrayList<SavedAccount>()
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
val a = column.access_info
|
|
|
|
|
if(done_list.contains(a)) continue
|
|
|
|
|
done_list.add(a)
|
|
|
|
|
if(! a.isNA) a.reloadSetting(this@ActMain)
|
|
|
|
|
column.fireShowColumnHeader()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun reloadAccountSetting(account : SavedAccount) {
|
|
|
|
|
val done_list = ArrayList<SavedAccount>()
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
val a = column.access_info
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(a != account) continue
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(done_list.contains(a)) continue
|
|
|
|
|
done_list.add(a)
|
|
|
|
|
if(! a.isNA) a.reloadSetting(this@ActMain)
|
|
|
|
|
column.fireShowColumnHeader()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
fun closeColumn(column : Column, bConfirmed : Boolean = false) {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
|
|
|
|
if(column.dont_close) {
|
2018-01-21 13:46:36 +01:00
|
|
|
|
showToast(this, false, R.string.column_has_dont_close_option)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 20:06:15 +02:00
|
|
|
|
if(! bConfirmed && ! Pref.bpDontConfirmBeforeCloseColumn(pref)) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
|
.setMessage(R.string.confirm_close_column)
|
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
2018-09-20 18:41:04 +02:00
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> closeColumn(column, bConfirmed = true) }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
.show()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val page_delete = app_state.column_list.indexOf(column)
|
|
|
|
|
|
|
|
|
|
phoneTab({ env ->
|
|
|
|
|
val page_showing = env.pager.currentItem
|
|
|
|
|
|
|
|
|
|
removeColumn(column)
|
|
|
|
|
|
2019-08-07 02:53:53 +02:00
|
|
|
|
if(app_state.column_list.isNotEmpty() && page_delete > 0 && page_showing == page_delete) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val idx = page_delete - 1
|
2018-01-19 10:27:35 +01:00
|
|
|
|
scrollToColumn(idx)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val c = app_state.column_list[idx]
|
|
|
|
|
if(! c.bFirstInitialized) {
|
|
|
|
|
c.startLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 18:19:57 +01:00
|
|
|
|
}, {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
removeColumn(column)
|
|
|
|
|
|
2019-08-07 02:53:53 +02:00
|
|
|
|
if(app_state.column_list.isNotEmpty() && page_delete > 0) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val idx = page_delete - 1
|
2018-01-19 10:27:35 +01:00
|
|
|
|
scrollToColumn(idx)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val c = app_state.column_list[idx]
|
|
|
|
|
if(! c.bFirstInitialized) {
|
|
|
|
|
c.startLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 14:38:48 +02:00
|
|
|
|
fun closeColumnAll(
|
|
|
|
|
_lastColumnIndex : Int = - 1,
|
|
|
|
|
bConfirmed : Boolean = false
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
if(! bConfirmed) {
|
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
|
.setMessage(R.string.confirm_close_column_all)
|
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> closeColumnAll(_lastColumnIndex, true) }
|
|
|
|
|
.show()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lastColumnIndex = when(_lastColumnIndex) {
|
|
|
|
|
- 1 -> phoneTab(
|
2018-11-12 18:19:57 +01:00
|
|
|
|
{ it.pager.currentItem },
|
|
|
|
|
{ 0 }
|
2018-07-05 14:38:48 +02:00
|
|
|
|
)
|
|
|
|
|
else -> _lastColumnIndex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
|
|
|
|
|
|
|
|
|
for(i in (0 until app_state.column_list.size).reversed()) {
|
|
|
|
|
val column = app_state.column_list[i]
|
|
|
|
|
if(column.dont_close) continue
|
|
|
|
|
app_state.column_list.removeAt(i).dispose()
|
|
|
|
|
if(lastColumnIndex >= i) -- lastColumnIndex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
if(app_state.column_list.isNotEmpty() && lastColumnIndex >= 0 && lastColumnIndex < app_state.column_list.size) {
|
|
|
|
|
scrollToColumn(lastColumnIndex)
|
|
|
|
|
val c = app_state.column_list[lastColumnIndex]
|
|
|
|
|
if(! c.bFirstInitialized) {
|
|
|
|
|
c.startLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
// カラム追加系
|
|
|
|
|
|
2018-02-06 21:41:30 +01:00
|
|
|
|
fun addColumn(
|
|
|
|
|
indexArg : Int,
|
|
|
|
|
ai : SavedAccount,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
type : ColumnType,
|
2018-02-06 21:41:30 +01:00
|
|
|
|
vararg params : Any
|
|
|
|
|
) : Column {
|
|
|
|
|
return addColumn(
|
|
|
|
|
Pref.bpAllowColumnDuplication(pref),
|
|
|
|
|
indexArg,
|
|
|
|
|
ai,
|
|
|
|
|
type,
|
|
|
|
|
*params
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-02-08 05:14:46 +01:00
|
|
|
|
|
2018-02-06 21:41:30 +01:00
|
|
|
|
fun addColumn(
|
2018-02-08 05:14:46 +01:00
|
|
|
|
allowColumnDuplication : Boolean,
|
2018-02-06 21:41:30 +01:00
|
|
|
|
indexArg : Int,
|
|
|
|
|
ai : SavedAccount,
|
2019-08-23 01:49:20 +02:00
|
|
|
|
type : ColumnType,
|
2018-02-06 21:41:30 +01:00
|
|
|
|
vararg params : Any
|
|
|
|
|
) : Column {
|
2018-02-08 05:14:46 +01:00
|
|
|
|
if(! allowColumnDuplication) {
|
2018-02-06 21:41:30 +01:00
|
|
|
|
// 既に同じカラムがあればそこに移動する
|
|
|
|
|
for(column in app_state.column_list) {
|
|
|
|
|
if(column.isSameSpec(ai, type, params)) {
|
|
|
|
|
val indexColumn = app_state.column_list.indexOf(column)
|
|
|
|
|
scrollToColumn(indexColumn)
|
|
|
|
|
return column
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
2019-08-23 01:49:20 +02:00
|
|
|
|
val col = Column(app_state, ai, this, type.id, *params)
|
2018-02-06 21:41:30 +01:00
|
|
|
|
val index = addColumn(col, indexArg)
|
2018-01-19 10:27:35 +01:00
|
|
|
|
scrollToColumn(index)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(! col.bFirstInitialized) {
|
|
|
|
|
col.startLoading()
|
|
|
|
|
}
|
|
|
|
|
return col
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun openChromeTab(opener : ChromeTabOpener) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
log.d("openChromeTab url=%s", opener.url)
|
|
|
|
|
|
2019-12-22 17:55:24 +01:00
|
|
|
|
val accessInfo = opener.accessInfo
|
2019-04-04 04:10:42 +02:00
|
|
|
|
val whoRef = opener.whoRef
|
2019-04-12 22:19:15 +02:00
|
|
|
|
val whoAcct = if(whoRef != null) {
|
2019-12-22 17:55:24 +01:00
|
|
|
|
accessInfo?.getFullAcct(whoRef.get())
|
2019-04-12 22:19:15 +02:00
|
|
|
|
} else {
|
2019-04-04 04:10:42 +02:00
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:55:24 +01:00
|
|
|
|
if(opener.allowIntercept && accessInfo != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// ハッシュタグはいきなり開くのではなくメニューがある
|
2019-09-30 13:02:39 +02:00
|
|
|
|
val tagInfo = opener.url.findHashtagFromUrl()
|
2019-10-02 11:37:41 +02:00
|
|
|
|
if(tagInfo != null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
Action_HashTag.dialog(
|
2018-01-18 19:09:36 +01:00
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
|
|
|
|
opener.url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(tagInfo.second),
|
2019-09-30 13:02:39 +02:00
|
|
|
|
tagInfo.first,
|
2019-04-04 04:10:42 +02:00
|
|
|
|
opener.tagList,
|
|
|
|
|
whoAcct
|
2018-01-04 19:52:25 +01:00
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-30 13:02:39 +02:00
|
|
|
|
val statusInfo = opener.url.findStatusIdFromUrl()
|
2019-10-02 11:37:41 +02:00
|
|
|
|
if(statusInfo != null) {
|
2019-12-22 17:55:24 +01:00
|
|
|
|
if(accessInfo.isNA ||
|
2019-09-30 13:02:39 +02:00
|
|
|
|
statusInfo.statusId == null ||
|
2020-02-02 15:19:57 +01:00
|
|
|
|
statusInfo.host != accessInfo.host
|
2019-09-30 13:02:39 +02:00
|
|
|
|
) {
|
2019-01-28 19:02:09 +01:00
|
|
|
|
Action_Toot.conversationOtherInstance(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
2019-09-30 13:02:39 +02:00
|
|
|
|
statusInfo.url,
|
|
|
|
|
statusInfo.statusId,
|
|
|
|
|
statusInfo.host,
|
|
|
|
|
statusInfo.statusId
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Action_Toot.conversationLocal(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
accessInfo,
|
2019-09-30 13:02:39 +02:00
|
|
|
|
statusInfo.statusId
|
2019-01-28 19:02:09 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:55:24 +01:00
|
|
|
|
// opener.linkInfo をチェックしてメンションを判別する
|
|
|
|
|
val mention = opener.linkInfo?.mention
|
2020-01-10 14:42:37 +01:00
|
|
|
|
if(mention != null) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
val fullAcct = getFullAcctOrNull(accessInfo, mention.acct.ascii, mention.url)
|
2020-01-10 14:42:37 +01:00
|
|
|
|
if(fullAcct != null) {
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(fullAcct.host != null) {
|
|
|
|
|
when(fullAcct.host.ascii) {
|
2019-12-22 17:55:24 +01:00
|
|
|
|
"github.com",
|
|
|
|
|
"twitter.com" ->
|
|
|
|
|
App1.openCustomTab(this, mention.url)
|
|
|
|
|
"gmail.com" ->
|
2020-02-02 15:19:57 +01:00
|
|
|
|
App1.openBrowser(this, "mailto:${fullAcct.pretty}")
|
2019-12-22 17:55:24 +01:00
|
|
|
|
|
|
|
|
|
else ->
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
|
|
|
|
accessInfo, // FIXME nullが必要なケースがあったっけなかったっけ…
|
|
|
|
|
mention.url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
fullAcct.host,
|
|
|
|
|
fullAcct.username,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
original_url = opener.url
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-10 14:42:37 +01:00
|
|
|
|
|
2018-09-20 18:41:04 +02:00
|
|
|
|
// ユーザページをアプリ内で開く
|
2019-09-30 13:02:39 +02:00
|
|
|
|
var m = TootAccount.reAccountUrl.matcher(opener.url)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(m.find()) {
|
2019-09-12 16:05:18 +02:00
|
|
|
|
val host = m.groupEx(1) !!
|
|
|
|
|
val user = m.groupEx(2) !!.decodePercent()
|
2020-02-02 15:19:57 +01:00
|
|
|
|
val instance = m.groupEx(3)?.decodePercent()?.notEmpty()
|
2018-12-13 00:27:00 +01:00
|
|
|
|
// https://misskey.xyz/@tateisu@github.com
|
|
|
|
|
// https://misskey.xyz/@tateisu@twitter.com
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
|
if(instance != null) {
|
|
|
|
|
val instanceHost = Host.parse(instance)
|
|
|
|
|
when(instanceHost.ascii) {
|
2019-01-28 19:02:09 +01:00
|
|
|
|
"github.com", "twitter.com" -> {
|
2018-12-13 00:27:00 +01:00
|
|
|
|
App1.openCustomTab(this, "https://$instance/$user")
|
|
|
|
|
}
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
|
|
|
|
"gmail.com" -> {
|
2018-12-13 00:27:00 +01:00
|
|
|
|
App1.openBrowser(this, "mailto:$user@$instance")
|
|
|
|
|
}
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
|
|
|
|
else -> {
|
2018-12-13 00:27:00 +01:00
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
null, // Misskeyだと疑似アカが必要なんだっけ…?
|
2018-12-13 00:27:00 +01:00
|
|
|
|
"https://$instance/@$user",
|
2020-02-02 15:19:57 +01:00
|
|
|
|
instanceHost,
|
2019-02-13 08:17:49 +01:00
|
|
|
|
user,
|
|
|
|
|
original_url = opener.url
|
2018-12-13 00:27:00 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
} else {
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
accessInfo,
|
2018-09-20 18:41:04 +02:00
|
|
|
|
opener.url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(host),
|
2018-09-20 18:41:04 +02:00
|
|
|
|
user
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return
|
|
|
|
|
}
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2019-01-28 19:02:09 +01:00
|
|
|
|
m = TootAccount.reAccountUrl2.matcher(opener.url)
|
|
|
|
|
if(m.find()) {
|
2019-09-12 16:05:18 +02:00
|
|
|
|
val host = m.groupEx(1) !!
|
|
|
|
|
val user = m.groupEx(2) !!.decodePercent()
|
2019-01-28 19:02:09 +01:00
|
|
|
|
|
|
|
|
|
Action_User.profile(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
opener.pos,
|
2019-12-22 17:55:24 +01:00
|
|
|
|
accessInfo,
|
2019-01-28 19:02:09 +01:00
|
|
|
|
opener.url,
|
2020-02-02 15:19:57 +01:00
|
|
|
|
Host.parse(host),
|
2019-01-28 19:02:09 +01:00
|
|
|
|
user
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-12-22 17:55:24 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App1.openCustomTab(this, opener.url)
|
|
|
|
|
|
|
|
|
|
} catch(ex : Throwable) {
|
2018-01-28 20:03:04 +01:00
|
|
|
|
// warning.trace( ex );
|
2018-01-04 19:52:25 +01:00
|
|
|
|
log.e(ex, "openChromeTab failed. url=%s", opener.url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
fun showColumnMatchAccount(account : SavedAccount) {
|
|
|
|
|
for(column in app_state.column_list) {
|
2020-02-02 07:25:08 +01:00
|
|
|
|
if(account == column.access_info) {
|
2018-01-20 07:51:14 +01:00
|
|
|
|
column.fireRebindAdapterItems()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showFooterColor() {
|
2018-01-17 02:16:26 +01:00
|
|
|
|
val footer_button_bg_color = Pref.ipFooterButtonBgColor(pref)
|
|
|
|
|
val footer_button_fg_color = Pref.ipFooterButtonFgColor(pref)
|
|
|
|
|
val footer_tab_bg_color = Pref.ipFooterTabBgColor(pref)
|
|
|
|
|
val footer_tab_divider_color = Pref.ipFooterTabDividerColor(pref)
|
|
|
|
|
val footer_tab_indicator_color = Pref.ipFooterTabIndicatorColor(pref)
|
2018-11-19 23:46:14 +01:00
|
|
|
|
|
2019-01-28 19:02:09 +01:00
|
|
|
|
val colorBg = footer_button_bg_color.notZero() ?: getAttributeColor(
|
|
|
|
|
this,
|
|
|
|
|
R.attr.colorStatusButtonsPopupBg
|
|
|
|
|
)
|
|
|
|
|
val colorRipple =
|
|
|
|
|
footer_button_fg_color.notZero() ?: getAttributeColor(this, R.attr.colorRippleEffect)
|
2020-04-07 06:52:54 +02:00
|
|
|
|
btnMenu.backgroundDrawable = getAdaptiveRippleDrawableRound(this, colorBg, colorRipple)
|
|
|
|
|
btnToot.backgroundDrawable = getAdaptiveRippleDrawableRound(this, colorBg, colorRipple)
|
|
|
|
|
btnQuickToot.backgroundDrawable = getAdaptiveRippleDrawableRound(this, colorBg, colorRipple)
|
|
|
|
|
btnQuickTootMenu.backgroundDrawable =
|
|
|
|
|
getAdaptiveRippleDrawableRound(this, colorBg, colorRipple)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-01-18 16:33:53 +01:00
|
|
|
|
val csl = ColorStateList.valueOf(
|
|
|
|
|
footer_button_fg_color.notZero()
|
2019-01-28 19:02:09 +01:00
|
|
|
|
?: getAttributeColor(this, R.attr.colorVectorDrawable)
|
2019-01-18 16:33:53 +01:00
|
|
|
|
)
|
2019-01-17 20:40:51 +01:00
|
|
|
|
btnToot.imageTintList = csl
|
|
|
|
|
btnMenu.imageTintList = csl
|
|
|
|
|
btnQuickToot.imageTintList = csl
|
2019-04-12 22:19:15 +02:00
|
|
|
|
btnQuickTootMenu.imageTintList = csl
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-01-20 22:04:57 +01:00
|
|
|
|
var c = footer_tab_bg_color.notZero()
|
2019-01-18 16:33:53 +01:00
|
|
|
|
?: getAttributeColor(this, R.attr.colorColumnStripBackground)
|
2018-11-19 23:46:14 +01:00
|
|
|
|
svColumnStrip.setBackgroundColor(c)
|
|
|
|
|
llQuickTootBar.setBackgroundColor(c)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2019-01-18 16:33:53 +01:00
|
|
|
|
c = footer_tab_divider_color.notZero()
|
|
|
|
|
?: getAttributeColor(this, R.attr.colorImageButton)
|
2018-11-19 23:46:14 +01:00
|
|
|
|
vFooterDivider1.setBackgroundColor(c)
|
|
|
|
|
vFooterDivider2.setBackgroundColor(c)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-01-13 16:24:51 +01:00
|
|
|
|
llColumnStrip.indicatorColor = footer_tab_indicator_color
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// タブレット対応で必要になった関数など
|
|
|
|
|
|
|
|
|
|
private fun closeColumnSetting() : Boolean {
|
|
|
|
|
phoneTab({ env ->
|
|
|
|
|
val vh = env.pager_adapter.getColumnViewHolder(env.pager.currentItem)
|
2018-02-08 05:14:46 +01:00
|
|
|
|
if(vh?.isColumnSettingShown == true) {
|
2020-02-11 09:59:41 +01:00
|
|
|
|
vh.showColumnSetting(false)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return@closeColumnSetting true
|
|
|
|
|
}
|
|
|
|
|
}, { env ->
|
2018-01-10 16:47:35 +01:00
|
|
|
|
for(i in 0 until env.tablet_layout_manager.childCount) {
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
2019-08-07 02:53:53 +02:00
|
|
|
|
val columnViewHolder = when(val v = env.tablet_layout_manager.getChildAt(i)) {
|
2018-11-12 18:19:57 +01:00
|
|
|
|
null -> null
|
|
|
|
|
else -> (env.tablet_pager.getChildViewHolder(v) as? TabletColumnViewHolder)?.columnViewHolder
|
2018-09-27 16:21:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
if(columnViewHolder?.isColumnSettingShown == true) {
|
2020-02-11 09:59:41 +01:00
|
|
|
|
columnViewHolder.showColumnSetting(false)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
return@closeColumnSetting true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun addColumn(column : Column, indexArg : Int) : Int {
|
|
|
|
|
var index = indexArg
|
|
|
|
|
val size = app_state.column_list.size
|
|
|
|
|
if(index > size) index = size
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
app_state.column_list.add(index, column)
|
2018-01-17 02:16:26 +01:00
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
return index
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun removeColumn(column : Column) {
|
|
|
|
|
val idx_column = app_state.column_list.indexOf(column)
|
|
|
|
|
if(idx_column == - 1) return
|
|
|
|
|
|
2018-01-17 02:16:26 +01:00
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
|
|
|
|
app_state.column_list.removeAt(idx_column).dispose()
|
|
|
|
|
|
|
|
|
|
phoneTab(
|
2018-01-17 02:16:26 +01:00
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
2018-01-10 16:47:35 +01:00
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun setOrder(new_order : ArrayList<Int>) {
|
2018-01-17 02:16:26 +01:00
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2018-09-14 19:08:13 +02:00
|
|
|
|
val ie = app_state.column_list.size
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val tmp_list = ArrayList<Column>()
|
|
|
|
|
val used_set = HashSet<Int>()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
2018-09-14 19:08:13 +02:00
|
|
|
|
// copy by new_order
|
2018-01-04 19:52:25 +01:00
|
|
|
|
for(i in new_order) {
|
2018-09-20 18:41:04 +02:00
|
|
|
|
if(0 <= i && i < ie) {
|
2018-09-14 19:08:13 +02:00
|
|
|
|
used_set.add(i)
|
|
|
|
|
tmp_list.add(app_state.column_list[i])
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 19:08:13 +02:00
|
|
|
|
// dispose unused elements.
|
2018-09-20 18:41:04 +02:00
|
|
|
|
for(i in 0 until ie) {
|
2018-09-14 19:08:13 +02:00
|
|
|
|
if(used_set.contains(i)) continue
|
2018-01-04 19:52:25 +01:00
|
|
|
|
app_state.column_list[i].dispose()
|
|
|
|
|
}
|
|
|
|
|
app_state.column_list.clear()
|
|
|
|
|
app_state.column_list.addAll(tmp_list)
|
|
|
|
|
|
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
updateColumnStrip()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun resizeColumnWidth(env : TabletEnv) {
|
|
|
|
|
|
|
|
|
|
var column_w_min_dp = COLUMN_WIDTH_MIN_DP
|
2018-01-17 02:16:26 +01:00
|
|
|
|
val sv = Pref.spColumnWidth(pref)
|
2018-01-18 19:09:36 +01:00
|
|
|
|
if(sv.isNotEmpty()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
try {
|
|
|
|
|
val iv = Integer.parseInt(sv)
|
|
|
|
|
if(iv >= 100) {
|
|
|
|
|
column_w_min_dp = iv
|
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val dm = resources.displayMetrics
|
|
|
|
|
|
2018-11-24 08:04:42 +01:00
|
|
|
|
val screen_width = dm.widthPixels
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
val density = dm.density
|
|
|
|
|
var column_w_min = (0.5f + column_w_min_dp * density).toInt()
|
|
|
|
|
if(column_w_min < 1) column_w_min = 1
|
|
|
|
|
|
2018-11-30 11:54:32 +01:00
|
|
|
|
var column_w : Int
|
2018-11-24 08:04:42 +01:00
|
|
|
|
|
|
|
|
|
if(screen_width < column_w_min * 2) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 最小幅で2つ表示できないのなら1カラム表示
|
2019-11-14 07:37:45 +01:00
|
|
|
|
nScreenColumn = 1
|
2018-11-24 08:04:42 +01:00
|
|
|
|
column_w = screen_width
|
2018-01-04 19:52:25 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// カラム最小幅から計算した表示カラム数
|
2018-11-24 08:04:42 +01:00
|
|
|
|
nScreenColumn = screen_width / column_w_min
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(nScreenColumn < 1) nScreenColumn = 1
|
|
|
|
|
|
|
|
|
|
// データのカラム数より大きくならないようにする
|
|
|
|
|
// (でも最小は1)
|
|
|
|
|
val column_count = app_state.column_list.size
|
|
|
|
|
if(column_count > 0 && column_count < nScreenColumn) {
|
|
|
|
|
nScreenColumn = column_count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 表示カラム数から計算したカラム幅
|
2018-11-24 08:04:42 +01:00
|
|
|
|
column_w = screen_width / nScreenColumn
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// 最小カラム幅の1.5倍よりは大きくならないようにする
|
|
|
|
|
val column_w_max = (0.5f + column_w_min * 1.5f).toInt()
|
|
|
|
|
if(column_w > column_w_max) {
|
|
|
|
|
column_w = column_w_max
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 08:04:42 +01:00
|
|
|
|
nColumnWidth = column_w // dividerの幅を含む
|
2018-11-30 11:54:32 +01:00
|
|
|
|
|
2018-11-24 08:04:42 +01:00
|
|
|
|
val divider_width = (0.5f + 1f * density).toInt()
|
|
|
|
|
column_w -= divider_width
|
|
|
|
|
env.tablet_pager_adapter.columnWidth = column_w // dividerの幅を含まない
|
|
|
|
|
// env.tablet_snap_helper.columnWidth = column_w //使われていない
|
2018-11-30 11:54:32 +01:00
|
|
|
|
|
|
|
|
|
resizeAutoCW(column_w) // dividerの幅を含まない
|
2018-11-24 08:04:42 +01:00
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
// 並べ直す
|
|
|
|
|
env.tablet_pager_adapter.notifyDataSetChanged()
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-21 13:46:36 +01:00
|
|
|
|
private fun scrollToColumn(index : Int, smoothScroll : Boolean = true) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
scrollColumnStrip(index)
|
2018-01-10 16:47:35 +01:00
|
|
|
|
phoneTab(
|
2018-01-21 13:46:36 +01:00
|
|
|
|
|
2018-01-19 10:27:35 +01:00
|
|
|
|
// スマホはスムーススクロール基本ありだがたまにしない
|
2019-10-10 22:59:47 +02:00
|
|
|
|
{ env ->
|
|
|
|
|
log.d("ipLastColumnPos beforeScroll=${env.pager.currentItem}")
|
|
|
|
|
env.pager.setCurrentItem(index, smoothScroll)
|
|
|
|
|
},
|
2018-01-21 13:46:36 +01:00
|
|
|
|
|
2018-01-19 10:27:35 +01:00
|
|
|
|
// タブレットでスムーススクロールさせると頻繁にオーバーランするので絶対しない
|
2019-10-10 22:59:47 +02:00
|
|
|
|
{ env ->
|
|
|
|
|
log.d("ipLastColumnPos beforeScroll=${env.visibleColumnsIndices.first}")
|
|
|
|
|
env.tablet_pager.scrollToPosition(index)
|
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-27 16:21:37 +02:00
|
|
|
|
private fun importAppData(uri : Uri?) {
|
|
|
|
|
uri ?: return
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
|
// remove all columns
|
2020-04-07 06:52:54 +02:00
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
|
|
|
|
|
|
|
|
|
for(c in app_state.column_list) {
|
|
|
|
|
c.dispose()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2020-04-07 06:52:54 +02:00
|
|
|
|
app_state.column_list.clear()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
updateColumnStrip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runWithProgress(
|
|
|
|
|
"importing app data",
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
doInBackground = { progress ->
|
|
|
|
|
fun setProgressMessage(sv : String) =
|
|
|
|
|
runOnMainLooper { progress.setMessageEx(sv) }
|
2018-09-20 18:41:04 +02:00
|
|
|
|
|
|
|
|
|
var newColumnList : ArrayList<Column>? = null
|
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
setProgressMessage("import data to local storage...")
|
|
|
|
|
|
|
|
|
|
// アプリ内領域に一時ファイルを作ってコピーする
|
|
|
|
|
val cacheDir = cacheDir
|
|
|
|
|
cacheDir.mkdir()
|
|
|
|
|
val file = File(
|
|
|
|
|
cacheDir,
|
|
|
|
|
"SubwayTooter.${Process.myPid()}.${Process.myTid()}.tmp"
|
|
|
|
|
)
|
|
|
|
|
val source = contentResolver.openInputStream(uri)
|
|
|
|
|
if(source == null) {
|
|
|
|
|
showToast(true, "openInputStream failed.")
|
|
|
|
|
return@runWithProgress null
|
|
|
|
|
}
|
|
|
|
|
source.use { inStream ->
|
|
|
|
|
FileOutputStream(file).use { outStream ->
|
|
|
|
|
IOUtils.copy(inStream, outStream)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2020-04-07 06:52:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通知サービスを止める
|
|
|
|
|
setProgressMessage("syncing notification poller…")
|
|
|
|
|
PollingWorker.queueAppDataImportBefore(this@ActMain)
|
|
|
|
|
while(PollingWorker.mBusyAppDataImportBefore.get()) {
|
|
|
|
|
delay(1000L)
|
|
|
|
|
log.d("syncing polling task...")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// データを読み込む
|
|
|
|
|
setProgressMessage("reading app data...")
|
|
|
|
|
var zipEntryCount = 0
|
|
|
|
|
try {
|
|
|
|
|
ZipInputStream(FileInputStream(file)).use { zipStream ->
|
|
|
|
|
while(true) {
|
|
|
|
|
val entry = zipStream.nextEntry ?: break
|
|
|
|
|
++ zipEntryCount
|
|
|
|
|
try {
|
|
|
|
|
//
|
|
|
|
|
val entryName = entry.name
|
|
|
|
|
if(entryName.endsWith(".json")) {
|
|
|
|
|
newColumnList = AppDataExporter.decodeAppData(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
JsonReader(InputStreamReader(zipStream, "UTF-8"))
|
|
|
|
|
)
|
|
|
|
|
continue
|
2018-09-20 18:41:04 +02:00
|
|
|
|
}
|
2020-04-07 06:52:54 +02:00
|
|
|
|
|
|
|
|
|
if(AppDataExporter.restoreBackgroundImage(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
newColumnList,
|
|
|
|
|
zipStream,
|
|
|
|
|
entryName
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
zipStream.closeEntry()
|
2018-09-20 18:41:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
|
log.trace(ex)
|
2020-04-07 06:52:54 +02:00
|
|
|
|
if(zipEntryCount != 0) {
|
|
|
|
|
showToast(this@ActMain, ex, "importAppData failed.")
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2020-04-07 06:52:54 +02:00
|
|
|
|
// zipではなかった場合、zipEntryがない状態になる。例外はPH-1では出なかったが、出ても問題ないようにする。
|
|
|
|
|
if(zipEntryCount == 0) {
|
|
|
|
|
InputStreamReader(FileInputStream(file), "UTF-8").use { inStream ->
|
|
|
|
|
newColumnList = AppDataExporter.decodeAppData(
|
|
|
|
|
this@ActMain,
|
|
|
|
|
JsonReader(inStream)
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
newColumnList
|
|
|
|
|
},
|
|
|
|
|
afterProc = {
|
|
|
|
|
// cancelled.
|
|
|
|
|
if(it == null) return@runWithProgress
|
|
|
|
|
|
2018-01-13 07:15:52 +01:00
|
|
|
|
try {
|
2020-04-07 06:52:54 +02:00
|
|
|
|
phoneOnly { env -> env.pager.adapter = null }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
2020-04-07 06:52:54 +02:00
|
|
|
|
app_state.column_list.clear()
|
|
|
|
|
app_state.column_list.addAll(it)
|
|
|
|
|
app_state.saveColumnList()
|
|
|
|
|
|
|
|
|
|
phoneTab(
|
|
|
|
|
{ env -> env.pager.adapter = env.pager_adapter },
|
|
|
|
|
{ env -> resizeColumnWidth(env) }
|
|
|
|
|
)
|
|
|
|
|
updateColumnStrip()
|
2018-01-17 02:16:26 +01:00
|
|
|
|
} finally {
|
2018-01-13 07:15:52 +01:00
|
|
|
|
// 通知サービスをリスタート
|
|
|
|
|
PollingWorker.queueAppDataImportAfter(this@ActMain)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2020-02-01 09:13:51 +01:00
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
|
showToast(this@ActMain, true, R.string.import_completed_please_restart_app)
|
2020-02-01 09:13:51 +01:00
|
|
|
|
finish()
|
2020-04-07 06:52:54 +02:00
|
|
|
|
},
|
|
|
|
|
preProc = {
|
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
|
|
|
},
|
|
|
|
|
postProc = {
|
|
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
2020-04-07 06:52:54 +02:00
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDrawerSlide(drawerView : View, slideOffset : Float) {
|
|
|
|
|
post_helper.closeAcctPopup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDrawerOpened(drawerView : View) {
|
|
|
|
|
post_helper.closeAcctPopup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDrawerClosed(drawerView : View) {
|
|
|
|
|
post_helper.closeAcctPopup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDrawerStateChanged(newState : Int) {
|
|
|
|
|
post_helper.closeAcctPopup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun resizeAutoCW(column_w : Int) {
|
2018-01-17 02:16:26 +01:00
|
|
|
|
val sv = Pref.spAutoCWLines(pref)
|
2018-01-21 13:46:36 +01:00
|
|
|
|
nAutoCwLines = sv.optInt() ?: - 1
|
2018-01-04 19:52:25 +01:00
|
|
|
|
if(nAutoCwLines > 0) {
|
|
|
|
|
val lv_pad = (0.5f + 12 * density).toInt()
|
|
|
|
|
val icon_width = avatarIconSize
|
|
|
|
|
val icon_end = (0.5f + 4 * density).toInt()
|
|
|
|
|
nAutoCwCellWidth = column_w - lv_pad * 2 - icon_width - icon_end
|
|
|
|
|
}
|
|
|
|
|
// この後各カラムは再描画される
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun checkAutoCW(status : TootStatus, text : CharSequence) {
|
|
|
|
|
if(nAutoCwCellWidth <= 0) {
|
|
|
|
|
// 設定が無効
|
|
|
|
|
status.auto_cw = null
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var auto_cw = status.auto_cw
|
|
|
|
|
if(auto_cw != null && auto_cw.refActivity?.get() === this@ActMain && auto_cw.cell_width == nAutoCwCellWidth) {
|
|
|
|
|
// 以前に計算した値がまだ使える
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
|
if(auto_cw == null) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
auto_cw = TootStatus.AutoCW()
|
|
|
|
|
status.auto_cw = auto_cw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 計算時の条件(文字フォント、文字サイズ、カラム幅)を覚えておいて、再利用時に同じか確認する
|
|
|
|
|
auto_cw.refActivity = WeakReference(this@ActMain)
|
|
|
|
|
auto_cw.cell_width = nAutoCwCellWidth
|
|
|
|
|
auto_cw.decoded_spoiler_text = null
|
|
|
|
|
|
|
|
|
|
// テキストをレイアウトして行数を測定
|
|
|
|
|
|
|
|
|
|
val lp = LinearLayout.LayoutParams(nAutoCwCellWidth, LinearLayout.LayoutParams.WRAP_CONTENT)
|
|
|
|
|
val tv = TextView(this)
|
|
|
|
|
tv.layoutParams = lp
|
2019-01-28 19:02:09 +01:00
|
|
|
|
if(! timeline_font_size_sp.isNaN()) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
tv.textSize = timeline_font_size_sp
|
|
|
|
|
}
|
2019-12-15 16:34:46 +01:00
|
|
|
|
|
2019-10-22 20:56:24 +02:00
|
|
|
|
val fv = timeline_spacing
|
2019-12-15 16:34:46 +01:00
|
|
|
|
if(fv != null) tv.setLineSpacing(0f, fv)
|
|
|
|
|
|
2018-08-24 15:45:27 +02:00
|
|
|
|
tv.typeface = timeline_font
|
2018-01-04 19:52:25 +01:00
|
|
|
|
tv.text = text
|
|
|
|
|
tv.measure(
|
2018-01-18 19:09:36 +01:00
|
|
|
|
View.MeasureSpec.makeMeasureSpec(nAutoCwCellWidth, View.MeasureSpec.EXACTLY),
|
|
|
|
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
)
|
|
|
|
|
val l = tv.layout
|
|
|
|
|
if(l != null) {
|
|
|
|
|
auto_cw.originalLineCount = l.lineCount
|
|
|
|
|
val line_count = auto_cw.originalLineCount
|
|
|
|
|
|
2019-01-28 19:02:09 +01:00
|
|
|
|
if((nAutoCwLines > 0 && line_count > nAutoCwLines)
|
2018-11-30 11:54:32 +01:00
|
|
|
|
&& status.spoiler_text.isEmpty()
|
2018-11-11 13:17:36 +01:00
|
|
|
|
&& (status.mentions?.size ?: 0) <= nAutoCwLines
|
2018-01-18 19:09:36 +01:00
|
|
|
|
) {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
val sb = SpannableStringBuilder()
|
|
|
|
|
sb.append(getString(R.string.auto_cw_prefix))
|
|
|
|
|
sb.append(text, 0, l.getLineEnd(nAutoCwLines - 1))
|
|
|
|
|
var last = sb.length
|
|
|
|
|
while(last > 0) {
|
|
|
|
|
val c = sb[last - 1]
|
|
|
|
|
if(c == '\n' || Character.isWhitespace(c)) {
|
|
|
|
|
-- last
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if(last < sb.length) {
|
|
|
|
|
sb.delete(last, sb.length)
|
|
|
|
|
}
|
|
|
|
|
sb.append('…')
|
|
|
|
|
auto_cw.decoded_spoiler_text = sb
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 16:21:37 +02:00
|
|
|
|
private fun checkPrivacyPolicy() {
|
|
|
|
|
|
|
|
|
|
// 既に表示中かもしれない
|
2018-11-12 18:19:57 +01:00
|
|
|
|
if(dlgPrivacyPolicy?.get()?.isShowing == true) return
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
|
|
|
|
val res_id = when(getString(R.string.language_code)) {
|
|
|
|
|
"ja" -> R.raw.privacy_policy_ja
|
|
|
|
|
"fr" -> R.raw.privacy_policy_fr
|
|
|
|
|
else -> R.raw.privacy_policy_en
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// プライバシーポリシーデータの読み込み
|
|
|
|
|
val bytes = loadRawResource(res_id)
|
2018-11-12 18:19:57 +01:00
|
|
|
|
if(bytes.isEmpty()) return
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
|
|
|
|
// 同意ずみなら表示しない
|
|
|
|
|
val digest = bytes.digestSHA256().encodeBase64Url()
|
2018-11-12 18:19:57 +01:00
|
|
|
|
if(digest == Pref.spAgreedPrivacyPolicyDigest(pref)) return
|
2018-09-27 16:21:37 +02:00
|
|
|
|
|
|
|
|
|
val dialog = AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.privacy_policy)
|
2018-11-12 18:19:57 +01:00
|
|
|
|
.setMessage(bytes.decodeUTF8())
|
|
|
|
|
.setNegativeButton(R.string.cancel) { _, _ ->
|
2018-09-27 16:21:37 +02:00
|
|
|
|
finish()
|
|
|
|
|
}
|
2018-11-12 18:19:57 +01:00
|
|
|
|
.setOnCancelListener {
|
2018-09-27 16:21:37 +02:00
|
|
|
|
finish()
|
|
|
|
|
}
|
2018-11-12 18:19:57 +01:00
|
|
|
|
.setPositiveButton(R.string.agree) { _, _ ->
|
|
|
|
|
pref.edit().put(Pref.spAgreedPrivacyPolicyDigest, digest).apply()
|
2018-09-27 16:21:37 +02:00
|
|
|
|
}
|
|
|
|
|
.create()
|
|
|
|
|
dlgPrivacyPolicy = WeakReference(dialog)
|
|
|
|
|
dialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
|
}
|