parent
16b696f04e
commit
7d2cb5148f
|
@ -9,8 +9,8 @@ android {
|
|||
applicationId "jp.juggler.subwaytooter"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 26
|
||||
versionCode 134
|
||||
versionName "1.3.4"
|
||||
versionCode 135
|
||||
versionName "1.3.5"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
@ -47,11 +48,13 @@ import jp.juggler.subwaytooter.table.UserRelation;
|
|||
import jp.juggler.subwaytooter.util.BucketList;
|
||||
import jp.juggler.subwaytooter.api.DuplicateMap;
|
||||
import jp.juggler.subwaytooter.util.LogCategory;
|
||||
import jp.juggler.subwaytooter.util.VersionString;
|
||||
import jp.juggler.subwaytooter.util.WordTrieTree;
|
||||
import jp.juggler.subwaytooter.view.MyListView;
|
||||
import jp.juggler.subwaytooter.util.ScrollPosition;
|
||||
import jp.juggler.subwaytooter.util.Utils;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
class Column implements StreamReader.Callback {
|
||||
private static final LogCategory log = new LogCategory( "Column" );
|
||||
|
||||
|
@ -1144,7 +1147,7 @@ class Column implements StreamReader.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
String parseMaxId(TootApiResult result){
|
||||
@Nullable String parseMaxId( TootApiResult result ){
|
||||
if( result != null && result.link_older != null ){
|
||||
Matcher m = reMaxId.matcher( result.link_older );
|
||||
if( m.find() ) return m.group( 1 );
|
||||
|
@ -1152,6 +1155,8 @@ class Column implements StreamReader.Callback {
|
|||
return null;
|
||||
}
|
||||
|
||||
@NonNull static final VersionString version_1_6 = new VersionString("1.6");
|
||||
|
||||
void startLoading(){
|
||||
cancelLastTask();
|
||||
|
||||
|
@ -1181,8 +1186,8 @@ class Column implements StreamReader.Callback {
|
|||
return result;
|
||||
}
|
||||
|
||||
TootApiResult getInstanceInformation( TootApiClient client ){
|
||||
client.setInstance( instance_uri );
|
||||
TootApiResult getInstanceInformation( @NonNull TootApiClient client ,@Nullable String instance){
|
||||
if( instance != null ) client.setInstance( instance );
|
||||
TootApiResult result = client.request( "/api/v1/instance" );
|
||||
if( result != null && result.object != null ){
|
||||
Column.this.instance_information = TootInstance.parse( result.object );
|
||||
|
@ -1438,13 +1443,17 @@ class Column implements StreamReader.Callback {
|
|||
|
||||
default:
|
||||
case TAB_STATUS:
|
||||
if( access_info.isPseudo() ){
|
||||
return client.request( PATH_INSTANCE );
|
||||
}else{
|
||||
if( access_info.isPseudo() || Column.this.instance_information == null ){
|
||||
TootApiResult r2 = getInstanceInformation( client ,null );
|
||||
if( access_info.isPseudo() ) return r2;
|
||||
}
|
||||
{
|
||||
String s = String.format( Locale.JAPAN, PATH_ACCOUNT_STATUSES, profile_id );
|
||||
if( with_attachment ) s = s + "&only_media=1";
|
||||
|
||||
getStatusesPinned( client, s + "&pinned=1");
|
||||
if( Column.this.instance_information != null && Column.this.instance_information.isEnoughVersion(version_1_6) ){
|
||||
getStatusesPinned( client, s + "&pinned=1");
|
||||
}
|
||||
|
||||
return getStatuses( client, s );
|
||||
|
||||
|
@ -1586,7 +1595,7 @@ class Column implements StreamReader.Callback {
|
|||
return result;
|
||||
|
||||
case TYPE_INSTANCE_INFORMATION:
|
||||
return getInstanceInformation( client );
|
||||
return getInstanceInformation( client ,instance_uri);
|
||||
}
|
||||
}finally{
|
||||
try{
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package jp.juggler.subwaytooter.api.entity;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import jp.juggler.subwaytooter.util.LogCategory;
|
||||
import jp.juggler.subwaytooter.util.Utils;
|
||||
import jp.juggler.subwaytooter.util.VersionString;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class TootInstance {
|
||||
private static final LogCategory log = new LogCategory( "TootInstance" );
|
||||
|
||||
|
@ -24,6 +27,8 @@ public class TootInstance {
|
|||
|
||||
public String version;
|
||||
|
||||
public VersionString decoded_version;
|
||||
|
||||
@Nullable
|
||||
public static TootInstance parse( JSONObject src ){
|
||||
if( src == null ) return null;
|
||||
|
@ -34,6 +39,7 @@ public class TootInstance {
|
|||
dst.description = Utils.optStringX( src, "description" );
|
||||
dst.email = Utils.optStringX( src, "email" );
|
||||
dst.version = Utils.optStringX( src, "version" );
|
||||
dst.decoded_version = new VersionString( dst.version );
|
||||
return dst;
|
||||
}catch( Throwable ex ){
|
||||
log.trace( ex );
|
||||
|
@ -41,4 +47,12 @@ public class TootInstance {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isEnoughVersion( @NonNull VersionString check ){
|
||||
if( decoded_version.isEmpty() || check.isEmpty() ) return false;
|
||||
int i = VersionString.compare( decoded_version ,check );
|
||||
return i >= 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package jp.juggler.subwaytooter.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VersionString {
|
||||
static final LogCategory log = new LogCategory( "VersionString" );
|
||||
|
||||
final String src;
|
||||
|
||||
final ArrayList<Object> node_list = new ArrayList<>( );
|
||||
|
||||
|
||||
private static boolean isDelimiter( char c ){
|
||||
return c == '.' || c == ' ';
|
||||
}
|
||||
|
||||
public VersionString( @Nullable String src ){
|
||||
this.src = src;
|
||||
if( src == null ) return;
|
||||
int end = src.length();
|
||||
int next = 0;
|
||||
while( next < end ){
|
||||
char c = src.charAt( next );
|
||||
|
||||
if( isDelimiter( c ) ){
|
||||
// 先頭の区切り文字を無視する
|
||||
++ next;
|
||||
}else if( Character.isDigit( c ) ){
|
||||
// 数字列のノード
|
||||
int start = next++;
|
||||
while( next < end && Character.isDigit( src.charAt( next ) ) ) ++ next;
|
||||
BigInteger value = new BigInteger( src.substring( start, next ) );
|
||||
node_list.add( value );
|
||||
}else{
|
||||
// 区切り文字と数字以外の文字が並ぶノード
|
||||
int start = next++;
|
||||
while( next < end ){
|
||||
c = src.charAt( next );
|
||||
if( isDelimiter( c ) ) break;
|
||||
if( Character.isDigit( c ) ) break;
|
||||
++ next;
|
||||
}
|
||||
String value = src.substring( start, next );
|
||||
node_list.add( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return node_list.isEmpty();
|
||||
}
|
||||
|
||||
// return -1 if a<b , return 1 if a>b , return 0 if a==b
|
||||
public static int compare( @NonNull VersionString a, @NonNull VersionString b ){
|
||||
|
||||
for( int idx =0 ;; ++idx){
|
||||
Object ao = ( idx >= a.node_list.size() ? null : a.node_list.get( idx ) );
|
||||
Object bo = ( idx >= b.node_list.size() ? null : b.node_list.get( idx ) );
|
||||
if( ao == null ){
|
||||
// 1.0 < 1.0.n
|
||||
// 1.0 < 1.0 xxx
|
||||
return bo == null ? 0 : - 1;
|
||||
}else if( bo == null ){
|
||||
// 1.0.n > 1.0
|
||||
// 1.0 xxx > 1.0
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( ao instanceof BigInteger ){
|
||||
if( bo instanceof BigInteger ){
|
||||
// 数字同士の場合
|
||||
int i = ( (BigInteger) ao ).compareTo( (BigInteger) bo );
|
||||
if( i == 0 ) continue;
|
||||
return i;
|
||||
}else{
|
||||
// 数字 > 数字以外
|
||||
// 1.5.n > 1.5 xxx
|
||||
return 1;
|
||||
}
|
||||
}else if( bo instanceof BigInteger ){
|
||||
// 数字以外 < 数字
|
||||
// 1.5 xxx < 1.5.n
|
||||
return - 1;
|
||||
}else{
|
||||
// 数字じゃない文字列どうしは辞書順で比較
|
||||
int i = ( (String) ao ).compareTo( (String) bo );
|
||||
if( i == 0 ) continue;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue