Permalink
Browse files

リファクタ

  • Loading branch information...
tateisu committed Nov 30, 2018
1 parent 17ca252 commit fbe7485e066869ee0f4b277eee65218f9be7a1d5
Showing with 175 additions and 255 deletions.
  1. +2 −3 app/src/main/java/jp/juggler/subwaytooter/ActAbout.kt
  2. +9 −18 app/src/main/java/jp/juggler/subwaytooter/ActAccountSetting.kt
  3. +4 −4 app/src/main/java/jp/juggler/subwaytooter/ActColumnCustomize.kt
  4. +8 −13 app/src/main/java/jp/juggler/subwaytooter/ActCustomStreamListener.kt
  5. +5 −11 app/src/main/java/jp/juggler/subwaytooter/ActHighlightWordEdit.kt
  6. +16 −24 app/src/main/java/jp/juggler/subwaytooter/ActHighlightWordList.kt
  7. +1 −1 app/src/main/java/jp/juggler/subwaytooter/ActMain.kt
  8. +10 −10 app/src/main/java/jp/juggler/subwaytooter/ActMediaViewer.kt
  9. +4 −9 app/src/main/java/jp/juggler/subwaytooter/ActNickname.kt
  10. +10 −9 app/src/main/java/jp/juggler/subwaytooter/ActPost.kt
  11. +4 −9 app/src/main/java/jp/juggler/subwaytooter/App1.kt
  12. +9 −9 app/src/main/java/jp/juggler/subwaytooter/AppDataExporter.kt
  13. +13 −21 app/src/main/java/jp/juggler/subwaytooter/AppState.kt
  14. +5 −3 app/src/main/java/jp/juggler/subwaytooter/ColumnViewHolder.kt
  15. +3 −10 app/src/main/java/jp/juggler/subwaytooter/PollingWorker.kt
  16. +6 −13 app/src/main/java/jp/juggler/subwaytooter/ViewHolderHeaderInstance.kt
  17. +6 −14 app/src/main/java/jp/juggler/subwaytooter/action/Action_Account.kt
  18. +1 −2 app/src/main/java/jp/juggler/subwaytooter/action/Action_Toot.kt
  19. +5 −10 app/src/main/java/jp/juggler/subwaytooter/api/entity/TootAccount.kt
  20. +2 −23 app/src/main/java/jp/juggler/subwaytooter/util/HTMLDecoder.kt
  21. +2 −33 app/src/main/java/jp/juggler/subwaytooter/util/MisskeyMarkdownDecoder.kt
  22. +2 −2 app/src/main/java/jp/juggler/subwaytooter/util/StorageUtils.kt
  23. +48 −4 app/src/main/java/jp/juggler/subwaytooter/util/Utils.kt
@@ -3,14 +3,13 @@ package jp.juggler.subwaytooter
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import jp.juggler.subwaytooter.util.LogCategory
import jp.juggler.subwaytooter.util.toUri
class ActAbout : AppCompatActivity() {
@@ -109,7 +108,7 @@ class ActAbout : AppCompatActivity() {
private fun open_browser(url : String) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
startActivity(intent)
} catch(ex : Throwable) {
log.trace(ex,"open_browser failed.")
@@ -548,12 +548,11 @@ class ActAccountSetting
private fun open_browser(url : String) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
startActivity(intent)
} catch(ex : Throwable) {
log.trace(ex,"open_browser failed.")
}
}
private fun updateVisibility() {
@@ -694,18 +693,16 @@ class ActAccountSetting
override fun handleResult(result : TootApiResult?) {
result ?: return // cancelled.
val url = result.string
val uri = result.string.mayUri()
val error = result.error
when {
// URLをブラウザで開く
url != null -> {
when{
uri != null->{
val data = Intent()
data.data = Uri.parse(url)
data.data = uri
setResult(Activity.RESULT_OK, data)
finish()
}
// エラーを表示
error != null -> {
error != null ->{
showToast(this@ActAccountSetting, true, error)
log.e("can't get oauth browser URL. $error")
}
@@ -729,15 +726,9 @@ class ActAccountSetting
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, R.string.notification_sound)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false)
try {
val notification_sound_uri = this.notification_sound_uri
if(notification_sound_uri?.isNotEmpty() == true) {
intent.putExtra(
RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
Uri.parse(notification_sound_uri)
)
}
} catch(ignored : Throwable) {
notification_sound_uri.mayUri()?.let{uri->
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,uri)
}
val chooser = Intent.createChooser(intent, getString(R.string.notification_sound))
@@ -449,21 +449,21 @@ class ActColumnCustomize : AppCompatActivity(), View.OnClickListener, ColorPicke
private fun loadImage(ivColumnBackground : ImageView, url : String) {
try {
if(url.isEmpty()) {
if( url.isEmpty() ){
closeBitmaps()
return
} else if(url == last_image_uri) {
}else if(url == last_image_uri) {
// 今表示してるのと同じ
return
}
// 直前のBitmapを掃除する
closeBitmaps()
val uri = url.mayUri() ?: return
// 画像をロードして、成功したら表示してURLを覚える
val resize_max = (0.5f + 64f * density).toInt()
val uri = Uri.parse(url)
last_image_bitmap = createResizedBitmap(this, uri, resize_max)
if(last_image_bitmap != null) {
ivColumnBackground.setImageBitmap(last_image_bitmap)
@@ -3,7 +3,6 @@ package jp.juggler.subwaytooter
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.AsyncTask
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
@@ -13,14 +12,11 @@ import android.view.View
import android.widget.EditText
import android.widget.TextView
import jp.juggler.subwaytooter.api.TootApiClient
import org.hjson.JsonValue
import java.util.regex.Pattern
import jp.juggler.subwaytooter.table.SavedAccount
import jp.juggler.subwaytooter.util.*
import okhttp3.Request
import org.hjson.JsonValue
import java.util.regex.Pattern
class ActCustomStreamListener : AppCompatActivity(), View.OnClickListener, TextWatcher {
@@ -194,7 +190,7 @@ class ActCustomStreamListener : AppCompatActivity(), View.OnClickListener, TextW
while(true) {
if( ! Pref.bpSendAccessTokenToAppServer(Pref.pref(this@ActCustomStreamListener))){
if(! Pref.bpSendAccessTokenToAppServer(Pref.pref(this@ActCustomStreamListener))) {
addLog("we won't use push notification until 'SendAccessTokenToAppServer' is not set.")
break
}
@@ -254,21 +250,21 @@ class ActCustomStreamListener : AppCompatActivity(), View.OnClickListener, TextW
if("*" == strInstance) {
has_wildcard = true
} else if(reUpperCase.matcher(strInstance).find()) {
addLog(strInstance + " : instance URL must be lower case.")
addLog("$strInstance : instance URL must be lower case.")
has_error = true
continue
} else if(strInstance[strInstance.length - 1] == '/') {
addLog(strInstance + " : instance URL must not be trailed with '/'.")
addLog("$strInstance : instance URL must not be trailed with '/'.")
has_error = true
continue
} else if(! reInstanceURL.matcher(strInstance).find()) {
addLog(strInstance + " : instance URL is not like https://.....")
addLog("$strInstance : instance URL is not like https://.....")
has_error = true
continue
}
val entry_value = member.value
if(! entry_value.isObject) {
addLog(strInstance + " : value for this instance is not JSON Object.")
addLog("$strInstance : value for this instance is not JSON Object.")
has_error = true
continue
}
@@ -299,7 +295,7 @@ class ActCustomStreamListener : AppCompatActivity(), View.OnClickListener, TextW
if(! reUrl.matcher(sv).find()) {
addLog("$strInstance.$key : not like Url.")
has_error = true
} else if(Uri.parse(sv).scheme == "https") {
} else if(sv.startsWith("https://")) {
try {
addLog("check access to $sv …")
builder = Request.Builder().url(sv)
@@ -310,7 +306,6 @@ class ActCustomStreamListener : AppCompatActivity(), View.OnClickListener, TextW
addLog(ex.withCaption("$strInstance.$key : connect failed."))
has_error = true
}
}
}
}
@@ -10,15 +10,13 @@ import android.view.View
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.TextView
import com.jrummyapps.android.colorpicker.ColorPickerDialog
import com.jrummyapps.android.colorpicker.ColorPickerDialogListener
import org.json.JSONException
import jp.juggler.subwaytooter.table.HighlightWord
import jp.juggler.subwaytooter.util.LogCategory
import jp.juggler.subwaytooter.util.mayUri
import jp.juggler.subwaytooter.util.toJsonObject
import org.json.JSONException
class ActHighlightWordEdit
: AppCompatActivity(),
@@ -220,13 +218,9 @@ class ActHighlightWordEdit
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, R.string.notification_sound)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false)
try {
val sound_uri = item.sound_uri
val uri = if(sound_uri?.isEmpty() != false) null else Uri.parse(sound_uri)
if(uri != null) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri)
}
} catch(ignored : Throwable) {
item.sound_uri.mayUri()?.let { uri ->
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri)
}
val chooser = Intent.createChooser(intent, getString(R.string.notification_sound))
@@ -24,9 +24,7 @@ import java.util.ArrayList
import jp.juggler.subwaytooter.dialog.DlgTextInput
import jp.juggler.subwaytooter.table.HighlightWord
import jp.juggler.subwaytooter.util.LogCategory
import jp.juggler.subwaytooter.util.showToast
import jp.juggler.subwaytooter.util.toJsonObject
import jp.juggler.subwaytooter.util.*
class ActHighlightWordList : AppCompatActivity(), View.OnClickListener {
@@ -309,36 +307,30 @@ class ActHighlightWordList : AppCompatActivity(), View.OnClickListener {
val sound_type = item.sound_type
if(sound_type == HighlightWord.SOUND_TYPE_NONE) return
if(sound_type == HighlightWord.SOUND_TYPE_CUSTOM) {
val sound_uri = item.sound_uri
if(sound_uri?.isNotEmpty() == true) {
try {
val ringtone = RingtoneManager.getRingtone(this, Uri.parse(sound_uri))
fun Uri?.tryRingTone() : Boolean {
try {
if(this != null) {
val ringtone = RingtoneManager.getRingtone(this@ActHighlightWordList, this)
if(ringtone != null) {
stopLastRingtone()
last_ringtone = WeakReference(ringtone)
ringtone.play()
return
return true
}
} catch(ex : Throwable) {
log.trace(ex)
}
// fall thru 失敗したら通常の音を鳴らす
} catch(ex : Throwable) {
log.trace(ex)
}
return false
}
val uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
try {
val ringtone = RingtoneManager.getRingtone(this, uri)
if(ringtone != null) {
stopLastRingtone()
last_ringtone = WeakReference(ringtone)
ringtone.play()
}
} catch(ex : Throwable) {
log.trace(ex)
}
if(sound_type == HighlightWord.SOUND_TYPE_CUSTOM
&& item.sound_uri.mayUri().tryRingTone()
) return
// fall thru 失敗したら通常の音を鳴らす
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).tryRingTone()
}
@@ -1646,7 +1646,7 @@ class ActMain : AppCompatActivity()
}
// queryIntentActivities に渡すURLは実在しないホストのものにする
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://dummy.subwaytooter.club/"))
val intent = Intent(Intent.ACTION_VIEW, "https://dummy.subwaytooter.club/".toUri() )
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val resolveInfoList = packageManager.queryIntentActivities(intent, query_flag)
if(resolveInfoList.isEmpty()) {
@@ -325,7 +325,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
val mediaSource = ExtractorMediaSource.Factory(dataSourceFactory)
.setExtractorsFactory(extractorsFactory)
.createMediaSource(Uri.parse(url))
.createMediaSource(url.toUri())
mediaSource.addEventListener(App1.getAppState(this).handler, mediaSourceEventListener)
@@ -493,7 +493,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
// 画像の中心が原点に来るようにして
matrix.postTranslate(src_width * - 0.5f, src_height * - 0.5f)
// orientationに合わせた回転指定
val flipWh = when(orientation) {
2 -> {
@@ -545,11 +545,11 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
return bitmap
}
}
// 出力サイズ
val dst_width : Int
val dst_height : Int
when(flipWh){
when(flipWh) {
true -> {
dst_width = src_height
dst_height = src_width
@@ -732,7 +732,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
var fileName : String? = null
try {
val pathSegments = Uri.parse(url).pathSegments
val pathSegments = url.toUri().pathSegments
if(pathSegments != null) {
val size = pathSegments.size
for(i in size - 1 downTo 0) {
@@ -754,7 +754,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}
if(fileName.length >= 20) fileName = fileName.substring(fileName.length - 20)
val request = DownloadManager.Request(Uri.parse(url))
val request = DownloadManager.Request(url.toUri())
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
request.setTitle(fileName)
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI)
@@ -777,7 +777,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, url)
} else {
intent.data = Uri.parse(url)
intent.data = url.toUri()
}
startActivity(intent)
@@ -844,13 +844,13 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
url : String?,
action : String
) {
if(url?.isEmpty() != false) return
val uri = url.mayUri() ?: return
val caption = getString(R.string.open_browser_of, caption_prefix)
ad.addAction(caption) {
try {
val intent = Intent(action, Uri.parse(url))
val intent = Intent(action, uri)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
} catch(ex : Throwable) {
@@ -891,5 +891,5 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}
}
}
}
Oops, something went wrong.

0 comments on commit fbe7485

Please sign in to comment.