通知音が妙に多く鳴る現象を軽減
This commit is contained in:
parent
a8c56f509f
commit
b9460d9f50
|
@ -9,8 +9,8 @@ android {
|
|||
applicationId "jp.juggler.subwaytooter"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 25
|
||||
versionCode 10
|
||||
versionName "0.1.0"
|
||||
versionCode 11
|
||||
versionName "0.1.1"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
@ -190,8 +190,10 @@ public class AlarmService extends IntentService {
|
|||
private static final String PATH_NOTIFICATIONS = "/api/v1/notifications";
|
||||
|
||||
private void checkAccount( TootApiClient client, ArrayList< Data > data_list, SavedAccount account ){
|
||||
log.d("checkAccount account_db_id=%s",account.db_id);
|
||||
|
||||
NotificationTracking nr = NotificationTracking.load( account.db_id );
|
||||
|
||||
|
||||
// まずキャッシュされたデータを処理する
|
||||
HashSet< Long > duplicate_check = new HashSet<>();
|
||||
ArrayList< JSONObject > dst_array = new ArrayList<>();
|
||||
|
@ -437,8 +439,10 @@ public class AlarmService extends IntentService {
|
|||
JSONArray array = new JSONArray( nr.last_data );
|
||||
for( int i = array.length() - 1 ; i >= 0 ; -- i ){
|
||||
JSONObject src = array.optJSONObject( i );
|
||||
long id = src.optLong( "id" );
|
||||
dst_array.add( src );
|
||||
duplicate_check.add( src.optLong( "id" ) );
|
||||
duplicate_check.add( id );
|
||||
log.d("add old. id=%s",id);
|
||||
}
|
||||
}catch( JSONException ex ){
|
||||
ex.printStackTrace();
|
||||
|
@ -446,7 +450,10 @@ public class AlarmService extends IntentService {
|
|||
}
|
||||
for( TootNotification item : data.list ){
|
||||
try{
|
||||
if( duplicate_check.contains( item.id ) ) continue;
|
||||
if( duplicate_check.contains( item.id ) ){
|
||||
log.d("skip duplicate. id=%s",item.id);
|
||||
continue;
|
||||
}
|
||||
duplicate_check.add( item.id );
|
||||
|
||||
String type = item.type;
|
||||
|
@ -456,6 +463,7 @@ public class AlarmService extends IntentService {
|
|||
|| ( ! account.notification_favourite && TootNotification.TYPE_FAVOURITE.equals( type ) )
|
||||
|| ( ! account.notification_follow && TootNotification.TYPE_FOLLOW.equals( type ) )
|
||||
){
|
||||
log.d("skip by setting. id=%s",item.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -483,10 +491,14 @@ public class AlarmService extends IntentService {
|
|||
// 最新10件を保存
|
||||
JSONArray d = new JSONArray();
|
||||
for( int i = 0 ; i < 10 ; ++ i ){
|
||||
if( i >= dst_array.size() ) break;
|
||||
if( i >= dst_array.size() ){
|
||||
log.d("inject %s data",i);
|
||||
break;
|
||||
}
|
||||
d.put( dst_array.get( i ) );
|
||||
}
|
||||
nr.last_data = d.toString();
|
||||
|
||||
nr.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -633,14 +633,14 @@ class Column {
|
|||
Matcher m = reMaxId.matcher( sv );
|
||||
if( m.find() ){
|
||||
max_id = m.group( 1 );
|
||||
log.d( "col=%s,max_id=%s", this.hashCode(), max_id );
|
||||
//log.d( "col=%s,max_id=%s", this.hashCode(), max_id );
|
||||
}
|
||||
}
|
||||
if( bTop ){
|
||||
Matcher m = reSinceId.matcher( sv );
|
||||
if( m.find() ){
|
||||
since_id = m.group( 1 );
|
||||
log.d( "col=%s,since_id=%s", this.hashCode(), since_id );
|
||||
//log.d( "col=%s,since_id=%s", this.hashCode(), since_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
//package jp.juggler.subwaytooter.table;
|
||||
//
|
||||
//import android.content.ContentValues;
|
||||
//import android.database.Cursor;
|
||||
//import android.database.sqlite.SQLiteDatabase;
|
||||
//
|
||||
//import org.json.JSONException;
|
||||
//import org.json.JSONObject;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//
|
||||
//import jp.juggler.subwaytooter.App1;
|
||||
//import jp.juggler.subwaytooter.util.LogCategory;
|
||||
//
|
||||
//public class AccessToken {
|
||||
//
|
||||
// static final LogCategory log = new LogCategory( "AccessToken" );
|
||||
//
|
||||
// static final String table = "access_token";
|
||||
//
|
||||
// static final String COL_HOST = "h";
|
||||
// static final String COL_USER_MAIL = "um";
|
||||
//
|
||||
//
|
||||
// public String host;
|
||||
// public String user_mail;
|
||||
//
|
||||
// public static void onDBCreate( SQLiteDatabase db ){
|
||||
// db.execSQL(
|
||||
// "create table if not exists " + table
|
||||
// + "(_id INTEGER PRIMARY KEY"
|
||||
// + ",h text not null"
|
||||
// + ",um text not null"
|
||||
// + ",t text not null"
|
||||
// + ")"
|
||||
// );
|
||||
// db.execSQL(
|
||||
// "create unique index if not exists " + table + "_host on " + table
|
||||
// + "(h"
|
||||
// + ",um"
|
||||
// + ")"
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// public static void onDBUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ){
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public static JSONObject load( String instance, String user_mail ){
|
||||
// try{
|
||||
// Cursor cursor = App1.getDB().query( table, null, "h=? and um=?", new String[]{ instance, user_mail }, null, null, null );
|
||||
// try{
|
||||
// if( cursor.moveToFirst() ){
|
||||
// return new JSONObject( cursor.getString( cursor.getColumnIndex( COL_TOKEN ) ) );
|
||||
// }
|
||||
// }finally{
|
||||
// cursor.close();
|
||||
// }
|
||||
// }catch( Throwable ex ){
|
||||
// log.e( ex, "load failed." );
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public static void save( String host, String user_mail, String json ){
|
||||
// try{
|
||||
// ContentValues cv = new ContentValues();
|
||||
// cv.put( COL_HOST, host );
|
||||
// cv.put( COL_USER_MAIL, user_mail );
|
||||
// cv.put( COL_TOKEN, json );
|
||||
// App1.getDB().replace( table, null, cv );
|
||||
// }catch( Throwable ex ){
|
||||
// log.e( ex, "save failed." );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -3,6 +3,7 @@ package jp.juggler.subwaytooter.table;
|
|||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
import jp.juggler.subwaytooter.App1;
|
||||
import jp.juggler.subwaytooter.util.LogCategory;
|
||||
|
@ -12,7 +13,9 @@ public class NotificationTracking {
|
|||
private static final LogCategory log = new LogCategory( "NotificationTracking" );
|
||||
|
||||
private static final String table = "noti_trac";
|
||||
|
||||
|
||||
private static final String COL_ID = BaseColumns._ID;
|
||||
|
||||
// アカウントDBの行ID。 サーバ側のIDではない
|
||||
private static final String COL_ACCOUNT_DB_ID = "a";
|
||||
|
||||
|
@ -58,6 +61,7 @@ public class NotificationTracking {
|
|||
}
|
||||
}
|
||||
|
||||
private long id = -1L;
|
||||
private long account_db_id;
|
||||
public long last_load;
|
||||
public long nid_read;
|
||||
|
@ -77,6 +81,7 @@ public class NotificationTracking {
|
|||
Cursor cursor = App1.getDB().query( table, null,WHERE_AID, new String[]{ Long.toString( account_db_id ) }, null, null, null );
|
||||
try{
|
||||
if( cursor.moveToFirst() ){
|
||||
dst.id = cursor.getLong( cursor.getColumnIndex( COL_ID ) );
|
||||
dst.last_load = cursor.getLong( cursor.getColumnIndex( COL_LAST_LOAD ) );
|
||||
dst.nid_read = cursor.getLong( cursor.getColumnIndex( COL_NID_READ ) );
|
||||
dst.nid_show = cursor.getLong( cursor.getColumnIndex( COL_NID_SHOW ) );
|
||||
|
@ -86,6 +91,13 @@ public class NotificationTracking {
|
|||
|
||||
int idx_last_data = cursor.getColumnIndex( COL_LAST_DATA );
|
||||
dst.last_data = cursor.isNull( idx_last_data ) ? null : cursor.getString( idx_last_data );
|
||||
|
||||
log.d("load account_db_id=%s,post=%s,%s last_data=%s"
|
||||
,account_db_id
|
||||
,dst.post_id
|
||||
,dst.post_time
|
||||
,(dst.last_data ==null ? "null" : ""+dst.last_data.length())
|
||||
);
|
||||
}
|
||||
}finally{
|
||||
cursor.close();
|
||||
|
@ -104,11 +116,31 @@ public class NotificationTracking {
|
|||
cv.put( COL_NID_READ, nid_read );
|
||||
cv.put( COL_NID_SHOW, nid_show );
|
||||
cv.put( COL_LAST_DATA, last_data );
|
||||
App1.getDB().replace( table, null, cv );
|
||||
cv.put( COL_POST_ID, post_id);
|
||||
cv.put( COL_POST_TIME, post_time);
|
||||
if( id == -1L ){
|
||||
id = App1.getDB().insert( table,null,cv );
|
||||
log.d("save.insert account_db_id=%s,post=%s,%s last_data=%s"
|
||||
,account_db_id
|
||||
,post_id
|
||||
,post_time
|
||||
,(last_data ==null ? "null" : ""+last_data.length())
|
||||
);
|
||||
|
||||
}else{
|
||||
App1.getDB().update( table, cv, WHERE_AID, new String[]{ Long.toString( account_db_id ) } );
|
||||
log.d("save.update account_db_id=%s,post=%s,%s last_data=%s"
|
||||
,account_db_id
|
||||
,post_id
|
||||
,post_time
|
||||
,(last_data ==null ? "null" : ""+last_data.length())
|
||||
);
|
||||
}
|
||||
}catch( Throwable ex ){
|
||||
log.e( ex, "save failed." );
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePost(long post_id,long post_time){
|
||||
this.post_id = post_id;
|
||||
this.post_time = post_time;
|
||||
|
@ -116,9 +148,15 @@ public class NotificationTracking {
|
|||
ContentValues cv = new ContentValues();
|
||||
cv.put( COL_POST_ID, post_id );
|
||||
cv.put( COL_POST_TIME, post_time );
|
||||
App1.getDB().update( table, cv,WHERE_AID, new String[]{ Long.toString( account_db_id ) } );
|
||||
int rows = App1.getDB().update( table, cv,WHERE_AID, new String[]{ Long.toString( account_db_id ) } );
|
||||
log.d("updatePost account_db_id=%s,post=%s,%s last_data=%s"
|
||||
,account_db_id
|
||||
,post_id
|
||||
,post_time
|
||||
,(last_data ==null ? "null" : ""+last_data.length())
|
||||
);
|
||||
}catch( Throwable ex ){
|
||||
log.e( ex, "save failed." );
|
||||
log.e( ex, "updatePost failed." );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +185,7 @@ public class NotificationTracking {
|
|||
cv.put( COL_POST_ID, 0 );
|
||||
cv.put( COL_POST_TIME, 0 );
|
||||
App1.getDB().update( table, cv,null,null);
|
||||
|
||||
}catch( Throwable ex ){
|
||||
log.e( ex, "save failed." );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue