リファクタ
This commit is contained in:
parent
648c2b4a79
commit
a52b767b10
Binary file not shown.
|
@ -5,13 +5,13 @@ apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 26
|
compileSdkVersion 26
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion '27.0.2'
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "jp.juggler.subwaytooter"
|
applicationId "jp.juggler.subwaytooter"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 179
|
versionCode 181
|
||||||
versionName "1.7.9"
|
versionName "1.8.1"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,26 +61,20 @@ dependencies {
|
||||||
compile 'com.android.support:design:26.1.0'
|
compile 'com.android.support:design:26.1.0'
|
||||||
compile 'com.android.support:customtabs:26.1.0'
|
compile 'com.android.support:customtabs:26.1.0'
|
||||||
|
|
||||||
compile 'com.google.firebase:firebase-core:11.4.2'
|
compile 'com.google.firebase:firebase-core:11.6.2'
|
||||||
compile 'com.google.firebase:firebase-messaging:11.4.2'
|
compile 'com.google.firebase:firebase-messaging:11.6.2'
|
||||||
|
|
||||||
// compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
// compile 'com.android.volley:volley:1.0.0'
|
|
||||||
compile 'com.squareup.okhttp3:okhttp:3.8.1'
|
compile 'com.squareup.okhttp3:okhttp:3.8.1'
|
||||||
// compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0' // Vollery に使う
|
|
||||||
compile 'commons-io:commons-io:2.4'
|
compile 'commons-io:commons-io:2.4'
|
||||||
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
|
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
|
||||||
compile 'com.github.woxthebox:draglistview:1.4.3'
|
compile 'com.github.woxthebox:draglistview:1.4.3'
|
||||||
compile 'com.github.omadahealth:swipy:1.2.3@aar'
|
compile 'com.github.omadahealth:swipy:1.2.3@aar'
|
||||||
compile 'com.jrummyapps:colorpicker:2.1.7'
|
compile 'com.jrummyapps:colorpicker:2.1.7'
|
||||||
// compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
|
|
||||||
compile 'com.github.kenglxn.QRGen:android:2.2.0'
|
compile 'com.github.kenglxn.QRGen:android:2.2.0'
|
||||||
compile project(':exif')
|
compile project(':exif')
|
||||||
|
|
||||||
compile 'com.github.bumptech.glide:glide:3.8.0'
|
compile 'com.github.bumptech.glide:glide:3.8.0'
|
||||||
// annotationProcessor 'com.github.bumptech.glide:compiler:3.8.0'
|
|
||||||
compile 'com.github.bumptech.glide:okhttp3-integration:1.5.0'
|
compile 'com.github.bumptech.glide:okhttp3-integration:1.5.0'
|
||||||
|
|
||||||
compile 'org.hjson:hjson:2.1.1'
|
compile 'org.hjson:hjson:2.1.1'
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -436,7 +436,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
|
||||||
if( who == null ){
|
if( who == null ){
|
||||||
// サーバのバグで誰のことか分からないので何もできない
|
// サーバのバグで誰のことか分からないので何もできない
|
||||||
}else if( relation.muting ){
|
}else if( relation.muting ){
|
||||||
activity.callMute( access_info, who, false,false, null );
|
activity.callMute( access_info, who, false,false );
|
||||||
}else{
|
}else{
|
||||||
View view = activity.getLayoutInflater().inflate( R.layout.dlg_confirm,null,false );
|
View view = activity.getLayoutInflater().inflate( R.layout.dlg_confirm,null,false );
|
||||||
TextView tvMessage = view.findViewById( R.id.tvMessage );
|
TextView tvMessage = view.findViewById( R.id.tvMessage );
|
||||||
|
@ -450,7 +450,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
|
||||||
.setNegativeButton( R.string.cancel, null )
|
.setNegativeButton( R.string.cancel, null )
|
||||||
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick( DialogInterface dialog, int which ){
|
@Override public void onClick( DialogInterface dialog, int which ){
|
||||||
activity.callMute( access_info, who, true,cbMuteNotification.isChecked(), null );
|
activity.callMute( access_info, who, true,cbMuteNotification.isChecked() );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.show();
|
.show();
|
||||||
|
@ -461,14 +461,14 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
|
||||||
if( who == null ){
|
if( who == null ){
|
||||||
// サーバのバグで誰のことか分からないので何もできない
|
// サーバのバグで誰のことか分からないので何もできない
|
||||||
}else if( relation.blocking ){
|
}else if( relation.blocking ){
|
||||||
activity.callBlock( access_info, who, false, null );
|
activity.callBlock( access_info, who, false );
|
||||||
}else{
|
}else{
|
||||||
new AlertDialog.Builder( activity )
|
new AlertDialog.Builder( activity )
|
||||||
.setMessage( activity.getString( R.string.confirm_block_user, who.username ) )
|
.setMessage( activity.getString( R.string.confirm_block_user, who.username ) )
|
||||||
.setNegativeButton( R.string.cancel, null )
|
.setNegativeButton( R.string.cancel, null )
|
||||||
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick( DialogInterface dialog, int which ){
|
@Override public void onClick( DialogInterface dialog, int which ){
|
||||||
activity.callBlock( access_info, who, true, null );
|
activity.callBlock( access_info, who, true );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.show();
|
.show();
|
||||||
|
@ -550,7 +550,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
|
||||||
.setNegativeButton( R.string.cancel, null )
|
.setNegativeButton( R.string.cancel, null )
|
||||||
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick( DialogInterface dialog, int which ){
|
@Override public void onClick( DialogInterface dialog, int which ){
|
||||||
activity.callDomainBlock( access_info, domain, true, null );
|
activity.callDomainBlock( access_info, domain, true );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.show();
|
.show();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package jp.juggler.subwaytooter;
|
package jp.juggler.subwaytooter;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -833,7 +832,7 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
.setNegativeButton( R.string.cancel, null )
|
.setNegativeButton( R.string.cancel, null )
|
||||||
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override public void onClick( DialogInterface dialog, int which ){
|
@Override public void onClick( DialogInterface dialog, int which ){
|
||||||
activity.callDomainBlock( access_info, domain, false, null );
|
activity.callDomainBlock( access_info, domain, false );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.show();
|
.show();
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
package jp.juggler.subwaytooter.api;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import jp.juggler.subwaytooter.ActMain;
|
||||||
|
import jp.juggler.subwaytooter.table.SavedAccount;
|
||||||
|
import jp.juggler.subwaytooter.util.Utils;
|
||||||
|
|
||||||
|
/*
|
||||||
|
AsyncTask customized version:
|
||||||
|
- avoid warning from android lint.
|
||||||
|
- has ProgressDialog.
|
||||||
|
- has TootApiClient.
|
||||||
|
- pass progress message from TootApiClient to ProgressDialog.
|
||||||
|
*/
|
||||||
|
public abstract class TootApiTask extends AsyncTask< Void, Void, TootApiResult > implements TootApiClient.Callback {
|
||||||
|
|
||||||
|
@NonNull protected final TootApiClient client;
|
||||||
|
|
||||||
|
public TootApiTask( ActMain _activity, SavedAccount access_info, boolean bShowProgress ){
|
||||||
|
this.client = new TootApiClient( _activity, this );
|
||||||
|
client.setAccount( access_info );
|
||||||
|
if( bShowProgress ) showProgress( _activity );
|
||||||
|
}
|
||||||
|
|
||||||
|
public TootApiTask( ActMain _activity, String instance, boolean bShowProgress ){
|
||||||
|
this.client = new TootApiClient( _activity, this );
|
||||||
|
client.setInstance( instance );
|
||||||
|
if( bShowProgress ) showProgress( _activity );
|
||||||
|
}
|
||||||
|
|
||||||
|
public TootApiTask( ActMain _activity, boolean bShowProgress ){
|
||||||
|
this.client = new TootApiClient( _activity, this );
|
||||||
|
if( bShowProgress ) showProgress( _activity );
|
||||||
|
}
|
||||||
|
|
||||||
|
public TootApiTask setProgressPrefix( String s ){
|
||||||
|
this.progress_prefix = s;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override public boolean isApiCancelled(){
|
||||||
|
return isCancelled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void publishApiProgress( final String s ){
|
||||||
|
if( progress != null ){
|
||||||
|
Utils.runOnMainThread( new Runnable() {
|
||||||
|
@Override public void run(){
|
||||||
|
if( ! TextUtils.isEmpty( progress_prefix ) ){
|
||||||
|
progress.setMessage( progress_prefix + "\n" + s );
|
||||||
|
}else{
|
||||||
|
progress.setMessage( s );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override protected abstract TootApiResult doInBackground( Void... voids );
|
||||||
|
|
||||||
|
protected abstract void handleResult( @Nullable TootApiResult result );
|
||||||
|
|
||||||
|
@Override protected final void onCancelled( TootApiResult result ){
|
||||||
|
onPostExecute( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected final void onPostExecute( TootApiResult result ){
|
||||||
|
dismissProgress();
|
||||||
|
handleResult( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private ProgressDialog progress;
|
||||||
|
private String progress_prefix;
|
||||||
|
|
||||||
|
private void showProgress( Activity activity ){
|
||||||
|
//noinspection deprecation
|
||||||
|
this.progress = new ProgressDialog( activity );
|
||||||
|
progress.setIndeterminate( true );
|
||||||
|
progress.setCancelable( true );
|
||||||
|
if( ! TextUtils.isEmpty( progress_prefix ) ){
|
||||||
|
progress.setMessage( progress_prefix );
|
||||||
|
}
|
||||||
|
progress.setOnCancelListener( new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel( DialogInterface dialog ){
|
||||||
|
TootApiTask.this.cancel( true );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissProgress(){
|
||||||
|
if( progress != null ){
|
||||||
|
try{
|
||||||
|
progress.dismiss();
|
||||||
|
}catch( Throwable ignored ){
|
||||||
|
// java.lang.IllegalArgumentException:
|
||||||
|
// at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
|
||||||
|
// at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
|
||||||
|
// at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
|
||||||
|
// at android.app.Dialog.dismissDialog(Dialog.java:341)
|
||||||
|
// at android.app.Dialog.dismiss(Dialog.java:324)
|
||||||
|
// at jp.juggler.subwaytooter.ActMain$10$1.onPostExecute(ActMain.java:867)
|
||||||
|
// at jp.juggler.subwaytooter.ActMain$10$1.onPostExecute(ActMain.java:837)
|
||||||
|
}finally{
|
||||||
|
progress = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -66,7 +66,7 @@ public class DlgListMemberAdd implements View.OnClickListener {
|
||||||
this.activity = _activity;
|
this.activity = _activity;
|
||||||
// this.target_user = who;
|
// this.target_user = who;
|
||||||
this.target_user_full_acct = _list_owner.getFullAcct( who );
|
this.target_user_full_acct = _list_owner.getFullAcct( who );
|
||||||
this.account_list = activity.makeAccountList( log, false, null );
|
this.account_list = activity.makeAccountListNonPseudo( log, null );
|
||||||
|
|
||||||
if( _list_owner.isPseudo() ){
|
if( _list_owner.isPseudo() ){
|
||||||
this.list_owner = null;
|
this.list_owner = null;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -833,9 +834,9 @@ public class Utils {
|
||||||
// JSONではなかった
|
// JSONではなかった
|
||||||
|
|
||||||
// HTMLならタグの除去を試みる
|
// HTMLならタグの除去を試みる
|
||||||
String ct = response.header("content-type");
|
String ct = response.header( "content-type" );
|
||||||
if( ct != null && ct.contains( "/html" ) ){
|
if( ct != null && ct.contains( "/html" ) ){
|
||||||
sv = new DecodeOptions().decodeHTML( null,null,sv ).toString();
|
sv = new DecodeOptions().decodeHTML( null, null, sv ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append( sv );
|
sb.append( sv );
|
||||||
|
@ -862,7 +863,7 @@ public class Utils {
|
||||||
}catch( Throwable ex ){
|
}catch( Throwable ex ){
|
||||||
log.trace( ex );
|
log.trace( ex );
|
||||||
}
|
}
|
||||||
return sb.toString().replaceAll( "\n+","\n" );
|
return sb.toString().replaceAll( "\n+", "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ScanViewCallback {
|
public interface ScanViewCallback {
|
||||||
|
@ -970,20 +971,20 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAttribute( NamedNodeMap attr_map, String name, String defval ){
|
public static String getAttribute( @NonNull NamedNodeMap attr_map, @NonNull String name, @Nullable String defval ){
|
||||||
Node node = attr_map.getNamedItem( name );
|
Node node = attr_map.getNamedItem( name );
|
||||||
if( node != null ) return node.getNodeValue();
|
if( node != null ) return node.getNodeValue();
|
||||||
return defval;
|
return defval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static String formatError( Throwable ex, String fmt, Object... args ){
|
public static String formatError( @NonNull Throwable ex, @NonNull String fmt, Object... args ){
|
||||||
if( args.length > 0 ) fmt = String.format( fmt, args );
|
if( args.length > 0 ) fmt = String.format( fmt, args );
|
||||||
return fmt + String.format( " :%s %s", ex.getClass().getSimpleName(), ex.getMessage() );
|
return fmt + String.format( " :%s %s", ex.getClass().getSimpleName(), ex.getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static String formatError( Throwable ex, Resources resources, int string_id, Object... args ){
|
public static String formatError( @NonNull Throwable ex, @NonNull Resources resources, int string_id, Object... args ){
|
||||||
return resources.getString( string_id, args ) + String.format( " :%s %s", ex.getClass().getSimpleName(), ex.getMessage() );
|
return resources.getString( string_id, args ) + String.format( " :%s %s", ex.getClass().getSimpleName(), ex.getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -999,57 +1000,40 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showToast( final Context context, final boolean bLong, final String fmt, final Object... args ){
|
private static WeakReference< Toast > refToast;
|
||||||
|
|
||||||
|
private static void showToastImpl( final Context context, final boolean bLong, final String message ){
|
||||||
runOnMainThread( new Runnable() {
|
runOnMainThread( new Runnable() {
|
||||||
@Override
|
@Override public void run(){
|
||||||
public void run(){
|
// 前回のトーストの表示を終了する
|
||||||
Toast.makeText(
|
Toast t = refToast == null ? null : refToast.get();
|
||||||
|
if( t != null ) t.cancel();
|
||||||
|
// 新しいトーストを作る
|
||||||
|
t = Toast.makeText(
|
||||||
context
|
context
|
||||||
, ( args.length == 0 ? fmt : String.format( fmt, args ) )
|
, message
|
||||||
, bLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT
|
, bLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT
|
||||||
).show();
|
);
|
||||||
|
t.show();
|
||||||
|
refToast = new WeakReference<>( t );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showToast( final Context context, final Throwable ex, final String fmt, final Object... args ){
|
public static void showToast( @NonNull Context context, boolean bLong, @NonNull String fmt, Object... args ){
|
||||||
runOnMainThread( new Runnable() {
|
showToastImpl( context, bLong, args.length == 0 ? fmt : String.format( fmt, args ) );
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
Toast.makeText(
|
|
||||||
context
|
|
||||||
, formatError( ex, fmt, args )
|
|
||||||
, Toast.LENGTH_LONG
|
|
||||||
).show();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showToast( final Context context, final boolean bLong, final int string_id, final Object... args ){
|
public static void showToast( @NonNull Context context, @NonNull Throwable ex, String fmt, Object... args ){
|
||||||
runOnMainThread( new Runnable() {
|
showToastImpl( context, true, formatError( ex, fmt, args ) );
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
|
|
||||||
Toast.makeText(
|
|
||||||
context
|
|
||||||
, context.getString( string_id, args )
|
|
||||||
, bLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT
|
|
||||||
).show();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showToast( final Context context, final Throwable ex, final int string_id, final Object... args ){
|
public static void showToast( @NonNull Context context, boolean bLong, int string_id, Object... args ){
|
||||||
runOnMainThread( new Runnable() {
|
showToastImpl( context, bLong, context.getString( string_id, args ) );
|
||||||
@Override
|
}
|
||||||
public void run(){
|
|
||||||
Toast.makeText(
|
public static void showToast( @NonNull Context context, @NonNull Throwable ex, int string_id, Object... args ){
|
||||||
context
|
showToastImpl( context, true, formatError( ex, context.getResources(), string_id, args ) );
|
||||||
, formatError( ex, context.getResources(), string_id, args )
|
|
||||||
, Toast.LENGTH_LONG
|
|
||||||
).show();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExternalStorageDocument( Uri uri ){
|
public static boolean isExternalStorageDocument( Uri uri ){
|
||||||
|
|
Loading…
Reference in New Issue