リファクタ

This commit is contained in:
tateisu 2017-12-12 05:59:23 +09:00
parent 648c2b4a79
commit a52b767b10
8 changed files with 390 additions and 868 deletions

Binary file not shown.

View File

@ -5,13 +5,13 @@ apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
buildToolsVersion '27.0.2'
defaultConfig {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 26
versionCode 179
versionName "1.7.9"
versionCode 181
versionName "1.8.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
@ -61,26 +61,20 @@ dependencies {
compile 'com.android.support:design: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-messaging:11.4.2'
// compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.google.firebase:firebase-messaging:11.6.2'
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-urlconnection:3.8.0' // Vollery 使
compile 'commons-io:commons-io:2.4'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.github.woxthebox:draglistview:1.4.3'
compile 'com.github.omadahealth:swipy:1.2.3@aar'
compile 'com.jrummyapps:colorpicker:2.1.7'
// compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.github.kenglxn.QRGen:android:2.2.0'
compile project(':exif')
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 'org.hjson:hjson:2.1.1'

File diff suppressed because it is too large Load Diff

View File

@ -436,7 +436,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
if( who == null ){
// サーバのバグで誰のことか分からないので何もできない
}else if( relation.muting ){
activity.callMute( access_info, who, false,false, null );
activity.callMute( access_info, who, false,false );
}else{
View view = activity.getLayoutInflater().inflate( R.layout.dlg_confirm,null,false );
TextView tvMessage = view.findViewById( R.id.tvMessage );
@ -450,7 +450,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
.setNegativeButton( R.string.cancel, null )
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
@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();
@ -461,14 +461,14 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
if( who == null ){
// サーバのバグで誰のことか分からないので何もできない
}else if( relation.blocking ){
activity.callBlock( access_info, who, false, null );
activity.callBlock( access_info, who, false );
}else{
new AlertDialog.Builder( activity )
.setMessage( activity.getString( R.string.confirm_block_user, who.username ) )
.setNegativeButton( R.string.cancel, null )
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
@Override public void onClick( DialogInterface dialog, int which ){
activity.callBlock( access_info, who, true, null );
activity.callBlock( access_info, who, true );
}
} )
.show();
@ -550,7 +550,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
.setNegativeButton( R.string.cancel, null )
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
@Override public void onClick( DialogInterface dialog, int which ){
activity.callDomainBlock( access_info, domain, true, null );
activity.callDomainBlock( access_info, domain, true );
}
} )
.show();

View File

@ -1,6 +1,5 @@
package jp.juggler.subwaytooter;
import android.app.Activity;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
@ -833,7 +832,7 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
.setNegativeButton( R.string.cancel, null )
.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() {
@Override public void onClick( DialogInterface dialog, int which ){
activity.callDomainBlock( access_info, domain, false, null );
activity.callDomainBlock( access_info, domain, false );
}
} )
.show();

View File

@ -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;
}
}
}
}

View File

@ -66,7 +66,7 @@ public class DlgListMemberAdd implements View.OnClickListener {
this.activity = _activity;
// this.target_user = 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() ){
this.list_owner = null;

View File

@ -10,6 +10,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -615,7 +616,7 @@ public class Utils {
int end = s.length();
int pos = s.indexOf( "%1$s" );
if( pos == - 1 ) return new SpannableString( s );
SpannableStringBuilder sb = new SpannableStringBuilder();
if( pos > 0 ) sb.append( s.substring( 0, pos ) );
sb.append( display_name );
@ -831,13 +832,13 @@ public class Utils {
}
if( sb.length() == empty_length ){
// JSONではなかった
// HTMLならタグの除去を試みる
String ct = response.header("content-type");
String ct = response.header( "content-type" );
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 );
}
}
@ -862,7 +863,7 @@ public class Utils {
}catch( Throwable ex ){
log.trace( ex );
}
return sb.toString().replaceAll( "\n+","\n" );
return sb.toString().replaceAll( "\n+", "\n" );
}
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 );
if( node != null ) return node.getNodeValue();
return defval;
}
@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 );
return fmt + String.format( " :%s %s", ex.getClass().getSimpleName(), ex.getMessage() );
}
@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() );
}
@ -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() {
@Override
public void run(){
Toast.makeText(
@Override public void run(){
// 前回のトーストの表示を終了する
Toast t = refToast == null ? null : refToast.get();
if( t != null ) t.cancel();
// 新しいトーストを作る
t = Toast.makeText(
context
, ( args.length == 0 ? fmt : String.format( fmt, args ) )
, message
, 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 ){
runOnMainThread( new Runnable() {
@Override
public void run(){
Toast.makeText(
context
, formatError( ex, fmt, args )
, Toast.LENGTH_LONG
).show();
}
} );
public static void showToast( @NonNull Context context, boolean bLong, @NonNull String fmt, Object... args ){
showToastImpl( context, bLong, args.length == 0 ? fmt : String.format( fmt, args ) );
}
public static void showToast( final Context context, final boolean bLong, final int string_id, final Object... args ){
runOnMainThread( new Runnable() {
@Override
public void run(){
Toast.makeText(
context
, context.getString( string_id, args )
, bLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT
).show();
}
} );
public static void showToast( @NonNull Context context, @NonNull Throwable ex, String fmt, Object... args ){
showToastImpl( context, true, formatError( ex, fmt, args ) );
}
public static void showToast( final Context context, final Throwable ex, final int string_id, final Object... args ){
runOnMainThread( new Runnable() {
@Override
public void run(){
Toast.makeText(
context
, formatError( ex, context.getResources(), string_id, args )
, Toast.LENGTH_LONG
).show();
}
} );
public static void showToast( @NonNull Context context, boolean bLong, int string_id, Object... args ){
showToastImpl( context, bLong, context.getString( string_id, args ) );
}
public static void showToast( @NonNull Context context, @NonNull Throwable ex, int string_id, Object... args ){
showToastImpl( context, true, formatError( ex, context.getResources(), string_id, args ) );
}
public static boolean isExternalStorageDocument( Uri uri ){