improved data model
This commit is contained in:
parent
d1c26006c4
commit
0e1ee9d999
|
@ -27,7 +27,6 @@ import org.mariotaku.restfu.http.ValueMap;
|
|||
*
|
||||
* @author Yusuke Yamamoto - yusuke at mac.com
|
||||
*/
|
||||
@Mapper(GeoLocationMapper.class)
|
||||
public class GeoLocation implements ValueMap {
|
||||
|
||||
double latitude;
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import com.bluelinelabs.logansquare.JsonMapper;
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.impl.GeoPoint;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/10/21.
|
||||
*/
|
||||
public class GeoLocationMapper extends JsonMapper<GeoLocation> {
|
||||
@Override
|
||||
public GeoLocation parse(JsonParser jsonParser) throws IOException {
|
||||
final GeoPoint geoPoint = LoganSquare.mapperFor(GeoPoint.class).parse(jsonParser);
|
||||
if (geoPoint == null) return null;
|
||||
return geoPoint.getGeoLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(GeoLocation object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@ public class CardEntityImpl implements CardEntity {
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class ImageValueImpl implements ImageValue {
|
||||
public static class ImageValueImpl implements ImageValue {
|
||||
@JsonField(name = "width")
|
||||
int width;
|
||||
@JsonField(name = "height")
|
||||
|
@ -96,7 +96,7 @@ public class CardEntityImpl implements CardEntity {
|
|||
|
||||
}
|
||||
|
||||
static class BooleanValueImpl implements BooleanValue {
|
||||
public static class BooleanValueImpl implements BooleanValue {
|
||||
|
||||
public BooleanValueImpl(boolean value) {
|
||||
this.value = value;
|
||||
|
@ -110,7 +110,7 @@ public class CardEntityImpl implements CardEntity {
|
|||
}
|
||||
}
|
||||
|
||||
static class StringValueImpl implements StringValue {
|
||||
public static class StringValueImpl implements StringValue {
|
||||
private final String value;
|
||||
|
||||
public StringValueImpl(String value) {
|
||||
|
@ -124,7 +124,7 @@ public class CardEntityImpl implements CardEntity {
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class UserValueImpl implements UserValue {
|
||||
public static class UserValueImpl implements UserValue {
|
||||
|
||||
@JsonField(name = "id")
|
||||
long userId;
|
||||
|
|
|
@ -32,7 +32,7 @@ public class HashtagEntityImpl implements HashtagEntity {
|
|||
|
||||
@JsonField(name = "text")
|
||||
String text;
|
||||
@JsonField(name = "indices")
|
||||
@JsonField(name = "indices", typeConverter = IndicesConverter.class)
|
||||
Indices indices;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
|
||||
package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
|
||||
import org.mariotaku.library.logansquare.extension.annotation.Mapper;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/3/31.
|
||||
*/
|
||||
@Mapper(IndicesMapper.class)
|
||||
public class Indices {
|
||||
|
||||
private int start, end;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
|
||||
import com.bluelinelabs.logansquare.JsonMapper;
|
||||
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
@ -27,9 +27,9 @@ import com.fasterxml.jackson.core.JsonToken;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/10/21.
|
||||
* Created by mariotaku on 15/11/11.
|
||||
*/
|
||||
public class IndicesMapper extends JsonMapper<Indices> {
|
||||
public class IndicesConverter implements TypeConverter<Indices> {
|
||||
@Override
|
||||
public Indices parse(JsonParser jsonParser) throws IOException {
|
||||
final int start, end;
|
||||
|
@ -42,7 +42,7 @@ public class IndicesMapper extends JsonMapper<Indices> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Indices object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
public void serialize(Indices instance, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
|
||||
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ public class QueryResultWrapper extends TwitterResponseImpl implements TwitterMo
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class SearchMetadata {
|
||||
public static class SearchMetadata {
|
||||
@JsonField(name = "max_id")
|
||||
long maxId;
|
||||
@JsonField(name = "since_id")
|
||||
|
|
|
@ -131,7 +131,7 @@ public class RelationshipImpl extends TwitterResponseImpl implements Relationshi
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class Target {
|
||||
public static class Target {
|
||||
@JsonField(name = "id")
|
||||
long id;
|
||||
@JsonField(name = "screen_name")
|
||||
|
@ -145,7 +145,7 @@ public class RelationshipImpl extends TwitterResponseImpl implements Relationshi
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class Source {
|
||||
public static class Source {
|
||||
@JsonField(name = "id")
|
||||
long id;
|
||||
@JsonField(name = "screen_name")
|
||||
|
|
|
@ -80,7 +80,7 @@ public class StatusImpl extends TwitterResponseImpl implements Status {
|
|||
UserImpl user;
|
||||
|
||||
@JsonField(name = "geo")
|
||||
GeoLocation geo;
|
||||
GeoPoint geo;
|
||||
|
||||
@JsonField(name = "place")
|
||||
Place place;
|
||||
|
@ -215,7 +215,8 @@ public class StatusImpl extends TwitterResponseImpl implements Status {
|
|||
|
||||
@Override
|
||||
public GeoLocation getGeoLocation() {
|
||||
return geo;
|
||||
if (geo == null) return null;
|
||||
return geo.getGeoLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -336,7 +337,7 @@ public class StatusImpl extends TwitterResponseImpl implements Status {
|
|||
}
|
||||
|
||||
@JsonObject
|
||||
static class CurrentUserRetweet {
|
||||
public static class CurrentUserRetweet {
|
||||
@JsonField(name = "id")
|
||||
long id;
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import edu.tsinghua.hotmobi.model.MediaEvent;
|
|||
import edu.tsinghua.hotmobi.model.NetworkEvent;
|
||||
import edu.tsinghua.hotmobi.model.NotificationEvent;
|
||||
import edu.tsinghua.hotmobi.model.RefreshEvent;
|
||||
import edu.tsinghua.hotmobi.model.ScreenEvent;
|
||||
import edu.tsinghua.hotmobi.model.ScrollRecord;
|
||||
import edu.tsinghua.hotmobi.model.SessionEvent;
|
||||
import edu.tsinghua.hotmobi.model.TweetEvent;
|
||||
|
@ -192,4 +193,8 @@ public class HotMobiLogger {
|
|||
public void logList(List<?> events, long accountId, String type) {
|
||||
mExecutor.execute(new WriteLogTask(mApplication, accountId, type, events));
|
||||
}
|
||||
|
||||
public static void logScreenEvent(Context context, ScreenEvent.Action action) {
|
||||
getInstance(context).log(ScreenEvent.create(context, action));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package edu.tsinghua.hotmobi.model;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/11/11.
|
||||
*/
|
||||
@JsonObject
|
||||
public class ScreenEvent extends BaseEvent {
|
||||
|
||||
@JsonField(name = "action", typeConverter = Action.ScreenActionConverter.class)
|
||||
Action action;
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public static ScreenEvent create(Context context, Action action) {
|
||||
final ScreenEvent event = new ScreenEvent();
|
||||
event.markStart(context);
|
||||
event.setAction(action);
|
||||
return event;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
ON("on"), OFF("off"), UNKNOWN("unknown");
|
||||
private final String value;
|
||||
|
||||
Action(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Action parse(String action) {
|
||||
if (ON.value.equalsIgnoreCase(action)) {
|
||||
return ON;
|
||||
} else if (OFF.value.equalsIgnoreCase(action)) {
|
||||
return OFF;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
public static class ScreenActionConverter extends StringBasedTypeConverter<Action> {
|
||||
|
||||
@Override
|
||||
public Action getFromString(String string) {
|
||||
return Action.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Action action) {
|
||||
if (action == null) return null;
|
||||
return action.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -47,6 +47,7 @@ import java.util.Arrays;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger;
|
||||
import edu.tsinghua.hotmobi.model.ScreenEvent;
|
||||
|
||||
import static org.mariotaku.twidere.util.ParseUtils.parseInt;
|
||||
import static org.mariotaku.twidere.util.Utils.getAccountIds;
|
||||
|
@ -146,6 +147,22 @@ public class RefreshService extends Service implements Constants {
|
|||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case Intent.ACTION_SCREEN_ON: {
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.ON);
|
||||
break;
|
||||
}
|
||||
case Intent.ACTION_SCREEN_OFF: {
|
||||
HotMobiLogger.logScreenEvent(context, ScreenEvent.Action.ON);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public IBinder onBind(final Intent intent) {
|
||||
return null;
|
||||
|
@ -177,7 +194,11 @@ public class RefreshService extends Service implements Constants {
|
|||
batteryFilter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||
batteryFilter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||||
batteryFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||||
final IntentFilter screenFilter = new IntentFilter();
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
registerReceiver(mPowerStateReceiver, batteryFilter);
|
||||
registerReceiver(mScreenStateReceiver, screenFilter);
|
||||
PowerStateReceiver.setServiceReceiverStarted(true);
|
||||
startAutoRefresh();
|
||||
}
|
||||
|
@ -185,6 +206,7 @@ public class RefreshService extends Service implements Constants {
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
PowerStateReceiver.setServiceReceiverStarted(false);
|
||||
unregisterReceiver(mScreenStateReceiver);
|
||||
unregisterReceiver(mPowerStateReceiver);
|
||||
unregisterReceiver(mStateReceiver);
|
||||
if (hasAutoRefreshAccounts(this)) {
|
||||
|
|
Loading…
Reference in New Issue