migrating to dagger
This commit is contained in:
parent
1a5cffbe5b
commit
8506b4c921
|
@ -83,6 +83,7 @@ dependencies {
|
|||
compile 'com.squareup:pollexor:2.0.4'
|
||||
compile 'com.squareup:tape:1.2.3'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'commons-primitives:commons-primitives:1.0'
|
||||
compile 'com.bluelinelabs:logansquare:1.1.0'
|
||||
compile 'ch.acra:acra:4.6.2'
|
||||
compile 'org.jraf:android-switch-backport:2.0.1'
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.util.Log;
|
|||
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
|
@ -71,6 +72,13 @@ public class WriteLogTask implements Runnable, Constants {
|
|||
fc = raf.getChannel();
|
||||
final FileLock lock = fc.lock();
|
||||
for (Object event : events) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
if (accountId > 0) {
|
||||
Log.v(HotMobiLogger.LOGTAG, "Log " + type + " for account " + accountId + ": " + event);
|
||||
} else {
|
||||
Log.v(HotMobiLogger.LOGTAG, "Log " + type + ": " + event);
|
||||
}
|
||||
}
|
||||
final byte[] bytes = LoganSquare.serialize(event).getBytes("UTF-8");
|
||||
final long start = raf.length();
|
||||
final ByteBuffer bb;
|
||||
|
|
|
@ -98,6 +98,16 @@ public class BaseEvent implements Parcelable {
|
|||
setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseEvent{" +
|
||||
"startTime=" + startTime +
|
||||
", endTime=" + endTime +
|
||||
", timeOffset=" + timeOffset +
|
||||
", location=" + location +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -33,6 +33,17 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
|||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class LatLng implements Parcelable {
|
||||
public static final Creator<LatLng> CREATOR = new Creator<LatLng>() {
|
||||
@Override
|
||||
public LatLng createFromParcel(Parcel in) {
|
||||
return new LatLng(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLng[] newArray(int size) {
|
||||
return new LatLng[size];
|
||||
}
|
||||
};
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "latitude")
|
||||
double latitude;
|
||||
|
@ -52,18 +63,6 @@ public class LatLng implements Parcelable {
|
|||
LatLngParcelablePlease.readFromParcel(this, in);
|
||||
}
|
||||
|
||||
public static final Creator<LatLng> CREATOR = new Creator<LatLng>() {
|
||||
@Override
|
||||
public LatLng createFromParcel(Parcel in) {
|
||||
return new LatLng(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLng[] newArray(int size) {
|
||||
return new LatLng[size];
|
||||
}
|
||||
};
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
@ -89,4 +88,12 @@ public class LatLng implements Parcelable {
|
|||
public void writeToParcel(Parcel dest, int flags) {
|
||||
LatLngParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LatLng{" +
|
||||
"latitude=" + latitude +
|
||||
", longitude=" + longitude +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,17 @@ import edu.tsinghua.hotmobi.TypeMappingUtil;
|
|||
@JsonObject
|
||||
public class LinkEvent extends BaseEvent implements Parcelable {
|
||||
|
||||
public static final Creator<LinkEvent> CREATOR = new Creator<LinkEvent>() {
|
||||
@Override
|
||||
public LinkEvent createFromParcel(Parcel in) {
|
||||
return new LinkEvent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkEvent[] newArray(int size) {
|
||||
return new LinkEvent[size];
|
||||
}
|
||||
};
|
||||
@JsonField(name = "link")
|
||||
String link;
|
||||
@JsonField(name = "type")
|
||||
|
@ -49,6 +60,14 @@ public class LinkEvent extends BaseEvent implements Parcelable {
|
|||
type = in.readString();
|
||||
}
|
||||
|
||||
public static LinkEvent create(Context context, String link, int typeInt) {
|
||||
final LinkEvent event = new LinkEvent();
|
||||
event.markStart(context);
|
||||
event.setLink(link);
|
||||
event.setType(TypeMappingUtil.getLinkType(typeInt));
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
@ -61,18 +80,6 @@ public class LinkEvent extends BaseEvent implements Parcelable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static final Creator<LinkEvent> CREATOR = new Creator<LinkEvent>() {
|
||||
@Override
|
||||
public LinkEvent createFromParcel(Parcel in) {
|
||||
return new LinkEvent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkEvent[] newArray(int size) {
|
||||
return new LinkEvent[size];
|
||||
}
|
||||
};
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
@ -81,11 +88,11 @@ public class LinkEvent extends BaseEvent implements Parcelable {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public static LinkEvent create(Context context, String link, int typeInt) {
|
||||
final LinkEvent event = new LinkEvent();
|
||||
event.markStart(context);
|
||||
event.setLink(link);
|
||||
event.setType(TypeMappingUtil.getLinkType(typeInt));
|
||||
return event;
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LinkEvent{" +
|
||||
"link='" + link + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
"} " + super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,5 +99,16 @@ public class MediaEvent extends BaseEvent {
|
|||
this.timelineType = timelineType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MediaEvent{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", tweetType=" + tweetType +
|
||||
", timelineType=" + timelineType +
|
||||
", previewUrl='" + previewUrl + '\'' +
|
||||
", mediaUrl='" + mediaUrl + '\'' +
|
||||
", previewEnabled=" + previewEnabled +
|
||||
"} " + super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,11 @@ public class NetworkEvent extends BaseEvent {
|
|||
public void setNetworkType(int networkType) {
|
||||
this.networkType = networkType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkEvent{" +
|
||||
"networkType=" + networkType +
|
||||
"} " + super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
|
|||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/8/8.
|
||||
*/
|
||||
|
@ -40,6 +42,14 @@ public class RefreshEvent extends BaseEvent {
|
|||
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
|
||||
TimelineType timelineType;
|
||||
|
||||
public static RefreshEvent create(final Context context, long[] ids, TimelineType timelineType) {
|
||||
final RefreshEvent event = new RefreshEvent();
|
||||
event.markStart(context);
|
||||
event.setIds(ids);
|
||||
event.setTimelineType(timelineType);
|
||||
return event;
|
||||
}
|
||||
|
||||
public void setIds(long[] ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
@ -48,11 +58,11 @@ public class RefreshEvent extends BaseEvent {
|
|||
this.timelineType = timelineType;
|
||||
}
|
||||
|
||||
public static RefreshEvent create(final Context context, long[] ids, TimelineType timelineType) {
|
||||
final RefreshEvent event = new RefreshEvent();
|
||||
event.markStart(context);
|
||||
event.setIds(ids);
|
||||
event.setTimelineType(timelineType);
|
||||
return event;
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RefreshEvent{" +
|
||||
"ids=" + Arrays.toString(ids) +
|
||||
", timelineType=" + timelineType +
|
||||
"} " + super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,4 +67,15 @@ public class ScrollRecord {
|
|||
public void setScrollState(int scrollState) {
|
||||
this.scrollState = scrollState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScrollRecord{" +
|
||||
"id=" + id +
|
||||
", accountId=" + accountId +
|
||||
", timestamp=" + timestamp +
|
||||
", timeOffset=" + timeOffset +
|
||||
", scrollState=" + scrollState +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
|
|||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
||||
|
||||
import org.mariotaku.twidere.model.AccountPreferences;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/8/8.
|
||||
*/
|
||||
|
@ -51,6 +56,9 @@ public class SessionEvent extends BaseEvent implements Parcelable {
|
|||
@ParcelableThisPlease
|
||||
@JsonField(name = "configuration")
|
||||
String configuration;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "preferences")
|
||||
HashMap<String, String> preferences;
|
||||
|
||||
protected SessionEvent(Parcel in) {
|
||||
super(in);
|
||||
|
@ -70,12 +78,42 @@ public class SessionEvent extends BaseEvent implements Parcelable {
|
|||
return event;
|
||||
}
|
||||
|
||||
public String getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
public void setPreferences(HashMap<String, String> preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
SessionEventParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public void dumpPreferences(Context context) {
|
||||
final HashMap<String, String> preferences = new HashMap<>();
|
||||
for (AccountPreferences pref : AccountPreferences.getAccountPreferences(context, Utils.getAccountIds(context))) {
|
||||
final long accountId = pref.getAccountId();
|
||||
preferences.put("notification_" + accountId + "_home", String.valueOf(pref.isHomeTimelineNotificationEnabled()));
|
||||
preferences.put("notification_" + accountId + "_interactions", String.valueOf(pref.isMentionsNotificationEnabled()));
|
||||
}
|
||||
setPreferences(preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SessionEvent{" +
|
||||
"configuration='" + configuration + '\'' +
|
||||
", preferences=" + preferences +
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -95,6 +95,17 @@ public class TweetEvent extends BaseEvent {
|
|||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TweetEvent{" +
|
||||
"id=" + id +
|
||||
", accountId=" + accountId +
|
||||
", userId=" + userId +
|
||||
", tweetType=" + tweetType +
|
||||
", timelineType=" + timelineType +
|
||||
", action=" + action +
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
OPEN("open"), RETWEET("retweet"), FAVORITE("favorite"), UNFAVORITE("unfavorite"),
|
||||
|
|
|
@ -30,6 +30,12 @@ import org.mariotaku.twidere.model.ParcelableStatus;
|
|||
public enum TweetType {
|
||||
TEXT("text"), PHOTO("photo"), VIDEO("video"), OTHER("other");
|
||||
|
||||
private final String value;
|
||||
|
||||
TweetType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static TweetType getTweetType(ParcelableStatus status) {
|
||||
if (status.media != null) {
|
||||
boolean hasImage = false;
|
||||
|
@ -52,16 +58,6 @@ public enum TweetType {
|
|||
return TEXT;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private final String value;
|
||||
|
||||
TweetType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static TweetType parse(String type) {
|
||||
if (TEXT.value.equalsIgnoreCase(type)) {
|
||||
return TEXT;
|
||||
|
@ -73,6 +69,10 @@ public enum TweetType {
|
|||
return OTHER;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static class TweetTypeConverter extends StringBasedTypeConverter<TweetType> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,26 +42,43 @@ import org.mariotaku.twidere.Constants;
|
|||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.util.ActivityTracker;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereColorUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
|
||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
|
||||
import org.mariotaku.twidere.view.TintedStatusFrameLayout;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity implements Constants,
|
||||
IThemedActivity, KeyboardShortcutsHandler.KeyboardShortcutCallback {
|
||||
|
||||
private TintedStatusFrameLayout mMainContent;
|
||||
|
||||
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
|
||||
@ShapeStyle
|
||||
private int mProfileImageStyle;
|
||||
private String mCurrentThemeBackgroundOption;
|
||||
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
|
||||
private String mCurrentThemeFontFamily;
|
||||
@Inject
|
||||
protected ActivityTracker mActivityTracker;
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mActivityTracker.dispatchStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mActivityTracker.dispatchStop(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentThemeFontFamily() {
|
||||
|
@ -146,6 +163,7 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity
|
|||
}
|
||||
setupWindow();
|
||||
super.onCreate(savedInstanceState);
|
||||
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
|
||||
mKeyboardShortcutsHandler = TwidereApplication.getInstance(this).getKeyboardShortcutsHandler();
|
||||
}
|
||||
|
||||
|
@ -204,11 +222,6 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -285,7 +298,7 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity
|
|||
if (mMainContent == null) return;
|
||||
|
||||
final int alpha = ThemeUtils.isTransparentBackground(getThemeBackgroundOption()) ? getCurrentThemeBackgroundAlpha() : 0xFF;
|
||||
final int statusBarColor=ThemeUtils.getActionBarColor(this, getCurrentThemeColor(), getCurrentThemeResourceId(), getThemeBackgroundOption());
|
||||
final int statusBarColor = ThemeUtils.getActionBarColor(this, getCurrentThemeColor(), getCurrentThemeResourceId(), getThemeBackgroundOption());
|
||||
mMainContent.setColor(statusBarColor, alpha);
|
||||
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(statusBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
|
||||
|
|
|
@ -26,11 +26,16 @@ import android.support.annotation.NonNull;
|
|||
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.util.ActivityTracker;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public abstract class BaseThemedActivity extends Activity implements IThemedActivity {
|
||||
|
||||
private int mCurrentThemeResource;
|
||||
|
@ -39,6 +44,20 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
|
|||
private String mCurrentThemeFontFamily;
|
||||
private String mCurrentThemeBackgroundOption;
|
||||
private int mProfileImageStyle;
|
||||
@Inject
|
||||
protected ActivityTracker mActivityTracker;
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mActivityTracker.dispatchStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mActivityTracker.dispatchStop(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentThemeFontFamily() {
|
||||
|
@ -100,6 +119,7 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
|
|||
StrictModeUtils.detectAllThreadPolicy();
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
|
||||
setActionBarBackground();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.mariotaku.twidere.R;
|
|||
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
|
||||
import org.mariotaku.twidere.util.ActivityStack;
|
||||
import org.mariotaku.twidere.util.ActivityTracker;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
|
||||
|
@ -53,7 +53,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
|
|||
// Utility classes
|
||||
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
|
||||
@Inject
|
||||
protected ActivityStack mActivityStack;
|
||||
protected ActivityTracker mActivityTracker;
|
||||
@Inject
|
||||
protected AsyncTwitterWrapper mTwitterWrapper;
|
||||
@Inject
|
||||
|
@ -157,7 +157,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mActivityStack.dispatchStart(this);
|
||||
mActivityTracker.dispatchStart(this);
|
||||
mIsVisible = true;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
|
|||
@Override
|
||||
protected void onStop() {
|
||||
mIsVisible = false;
|
||||
mActivityStack.dispatchStop(this);
|
||||
mActivityTracker.dispatchStop(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
private ControlBarShowHideHelper mControlBarShowHideHelper = new ControlBarShowHideHelper(this);
|
||||
private int mTabColumns;
|
||||
private View mActionBarContainer;
|
||||
private SessionEvent mSessionEvent;
|
||||
|
||||
public void closeAccountsDrawer() {
|
||||
if (mDrawerLayout == null) return;
|
||||
|
@ -429,9 +428,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
startService(new Intent(this, StreamingService.class));
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mSessionEvent = savedInstanceState.getParcelable(EXTRA_SESSION_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -444,11 +440,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
final Bus bus = TwidereApplication.getInstance(this).getMessageBus();
|
||||
assert bus != null;
|
||||
bus.register(this);
|
||||
// BEGIN HotMobi
|
||||
if (mSessionEvent == null) {
|
||||
mSessionEvent = SessionEvent.create(this);
|
||||
}
|
||||
// END HotMobi
|
||||
|
||||
mReadStateManager.registerOnSharedPreferenceChangeListener(mReadStateChangeListener);
|
||||
updateUnreadCount();
|
||||
}
|
||||
|
@ -481,14 +473,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
mPreferences.edit().putInt(KEY_SAVED_TAB_POSITION, mViewPager.getCurrentItem()).apply();
|
||||
sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONSTOP));
|
||||
|
||||
// BEGIN HotMobi
|
||||
final SessionEvent event = mSessionEvent;
|
||||
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||
if (event != null && isFinishing()) {
|
||||
event.markEnd();
|
||||
HotMobiLogger.getInstance(this).log(event);
|
||||
}
|
||||
// END HotMobi
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -502,7 +486,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(EXTRA_SESSION_EVENT, mSessionEvent);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.mariotaku.twidere.BuildConfig;
|
|||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.util.ActivityTracker;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
|
||||
|
@ -54,6 +55,8 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
|
|||
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
|
||||
@Inject
|
||||
protected AsyncTwitterWrapper mTwitterWrapper;
|
||||
@Inject
|
||||
protected ActivityTracker mActivityTracker;
|
||||
|
||||
// Data fields
|
||||
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
|
||||
|
@ -194,4 +197,16 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
|
|||
protected boolean shouldApplyWindowBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mActivityTracker.dispatchStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mActivityTracker.dispatchStop(this);
|
||||
super.onStop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,21 +22,48 @@ package org.mariotaku.twidere.util;
|
|||
|
||||
import android.app.Activity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import org.apache.commons.collections.primitives.ArrayIntList;
|
||||
import org.apache.commons.collections.primitives.IntList;
|
||||
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger;
|
||||
import edu.tsinghua.hotmobi.model.SessionEvent;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/10/5.
|
||||
*/
|
||||
public class ActivityStack {
|
||||
public class ActivityTracker {
|
||||
|
||||
private final HashSet<Integer> mInternalStack = new HashSet<>();
|
||||
private final IntList mInternalStack = new ArrayIntList();
|
||||
private SessionEvent mSessionEvent;
|
||||
|
||||
public void dispatchStart(Activity activity) {
|
||||
mInternalStack.add(System.identityHashCode(activity));
|
||||
// BEGIN HotMobi
|
||||
if (mSessionEvent == null) {
|
||||
mSessionEvent = SessionEvent.create(activity);
|
||||
}
|
||||
// END HotMobi
|
||||
}
|
||||
|
||||
public void dispatchStop(Activity activity) {
|
||||
mInternalStack.remove(System.identityHashCode(activity));
|
||||
|
||||
final int hashCode = System.identityHashCode(activity);
|
||||
|
||||
// BEGIN HotMobi
|
||||
final SessionEvent event = mSessionEvent;
|
||||
if (event != null && !isSwitchingInSameTask(hashCode)) {
|
||||
event.dumpPreferences(activity);
|
||||
event.markEnd();
|
||||
HotMobiLogger.getInstance(activity).log(event);
|
||||
mSessionEvent = null;
|
||||
}
|
||||
// END HotMobi
|
||||
|
||||
mInternalStack.removeElement(hashCode);
|
||||
}
|
||||
|
||||
private boolean isSwitchingInSameTask(int hashCode) {
|
||||
return mInternalStack.lastIndexOf(hashCode) < mInternalStack.size() - 1;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
|
@ -47,5 +74,4 @@ public class ActivityStack {
|
|||
return mInternalStack.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
package org.mariotaku.twidere.util.dagger;
|
||||
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.util.ActivityStack;
|
||||
import org.mariotaku.twidere.util.ActivityTracker;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
|
||||
|
@ -33,19 +33,19 @@ import dagger.Provides;
|
|||
@Module
|
||||
public class ApplicationModule {
|
||||
|
||||
private final ActivityStack activityStack;
|
||||
private final ActivityTracker activityTracker;
|
||||
private final AsyncTwitterWrapper asyncTwitterWrapper;
|
||||
private final ReadStateManager readStateManager;
|
||||
|
||||
public ApplicationModule(TwidereApplication application) {
|
||||
activityStack = new ActivityStack();
|
||||
activityTracker = new ActivityTracker();
|
||||
asyncTwitterWrapper = new AsyncTwitterWrapper(application);
|
||||
readStateManager = new ReadStateManager(application);
|
||||
}
|
||||
|
||||
@Provides
|
||||
ActivityStack provideActivityStack() {
|
||||
return activityStack;
|
||||
ActivityTracker provideActivityStack() {
|
||||
return activityTracker;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -58,8 +58,8 @@ public class ApplicationModule {
|
|||
return readStateManager;
|
||||
}
|
||||
|
||||
public ActivityStack getActivityStack() {
|
||||
return activityStack;
|
||||
public ActivityTracker getActivityTracker() {
|
||||
return activityTracker;
|
||||
}
|
||||
|
||||
public AsyncTwitterWrapper getAsyncTwitterWrapper() {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.mariotaku.twidere.util.dagger.component;
|
||||
|
||||
import org.mariotaku.twidere.activity.BasePreferenceActivity;
|
||||
import org.mariotaku.twidere.activity.BaseThemedActivity;
|
||||
import org.mariotaku.twidere.fragment.BaseFragment;
|
||||
import org.mariotaku.twidere.fragment.support.BaseSupportFragment;
|
||||
import org.mariotaku.twidere.util.MultiSelectEventHandler;
|
||||
|
@ -39,4 +41,8 @@ public interface GeneralComponent {
|
|||
void inject(BaseSupportFragment object);
|
||||
|
||||
void inject(MultiSelectEventHandler object);
|
||||
|
||||
void inject(BasePreferenceActivity object);
|
||||
|
||||
void inject(BaseThemedActivity object);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue