1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-18 03:28:55 +01:00

migrating to dagger

This commit is contained in:
Mariotaku Lee 2015-10-05 18:00:07 +08:00
parent 5abcdaab5f
commit 1a5cffbe5b
80 changed files with 1299 additions and 522 deletions

View File

@ -8,8 +8,8 @@ buildscript {
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
classpath('fr.avianey.androidsvgdrawable:gradle-plugin:1.0.2') {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath('fr.avianey.androidsvgdrawable:gradle-plugin:2.0.0') {
// should be excluded to avoid conflict
exclude group: 'xerces'
}

View File

@ -18,7 +18,7 @@
*/
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
buildToolsVersion '23.0.1'
lintOptions {
abortOnError false

View File

@ -39,8 +39,8 @@ android {
dependencies {
apt 'com.bluelinelabs:logansquare-compiler:1.1.0'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.1'
compile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:support-annotations:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.bluelinelabs:logansquare:1.1.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.github.mariotaku:RestFu:0.9.2'

View File

@ -23,7 +23,7 @@ apply from: rootProject.file('global.gradle')
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

View File

@ -36,7 +36,7 @@ android {
}
dependencies {
compile 'com.google.android.support:wearable:1.2.0'
compile 'com.google.android.support:wearable:1.3.0'
compile project(':twidere.component.nyan')
compile fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@ -24,7 +24,7 @@ android {
defaultConfig {
applicationId "org.mariotaku.twidere.extension.launcher.compose"
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

View File

@ -23,7 +23,7 @@ apply from: rootProject.file('global.gradle')
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

View File

@ -41,6 +41,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.0'
compile 'com.google.android.gms:play-services-wearable:7.5.0'
compile 'com.google.android.support:wearable:1.3.0'
compile 'com.google.android.gms:play-services-wearable:8.1.0'
}

View File

@ -58,19 +58,20 @@ dependencies {
// wearApp project(':twidere.wear')
apt 'com.bluelinelabs:logansquare-compiler:1.1.0'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.1'
apt 'com.google.dagger:dagger-compiler:2.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v13:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:support-v13:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.twitter:twitter-text:1.12.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.squareup:otto:1.3.8'
compile 'dnsjava:dnsjava:2.1.7'
compile 'com.commonsware.cwac:merge:1.1.1'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.0'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'com.pnikosis:materialish-progress:1.7'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.7'
compile 'com.github.johnpersano:supertoasts:1.3.4.1@aar'
@ -79,28 +80,30 @@ dependencies {
compile 'com.github.uucky:ColorPicker-Android:0.9.7@aar'
compile 'com.github.boxme:asyncmanager:1.0.0'
compile 'com.sprylab.android.texturevideoview:texturevideoview:1.0.1'
compile 'com.squareup:pollexor:2.0.3'
compile 'com.squareup:pollexor:2.0.4'
compile 'com.squareup:tape:1.2.3'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.bluelinelabs:logansquare:1.1.0'
compile 'ch.acra:acra:4.6.2'
compile 'org.jraf:android-switch-backport:2.0.1'
compile 'com.fasterxml.jackson.jr:jackson-jr-objects:2.6.1'
compile 'com.fasterxml.jackson.jr:jackson-jr-objects:2.6.2'
compile 'com.makeramen:roundedimageview:2.1.1'
compile 'com.soundcloud.android:android-crop:1.0.0@aar'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.github.mariotaku:PickNCrop:44b09cbc69'
compile 'com.diogobernardino:williamchart:2.0.1'
compile 'com.lnikkila:extendedtouchview:0.1.0'
googleCompile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.dagger:dagger:2.0.1'
googleCompile 'com.google.android.gms:play-services-maps:8.1.0'
googleCompile 'com.google.maps.android:android-maps-utils:0.4'
fdroidCompile 'org.osmdroid:osmdroid-android:4.3'
fdroidCompile 'org.slf4j:slf4j-simple:1.7.12'
debugCompile 'com.facebook.stetho:stetho:1.1.1'
debugCompile 'com.facebook.stetho:stetho-okhttp:1.1.1'
debugCompile 'com.facebook.stetho:stetho:1.2.0'
debugCompile 'com.facebook.stetho:stetho-okhttp:1.2.0'
compile project(':twidere.component.common')
compile project(':twidere.component.nyan')
compile fileTree(dir: 'libs/main', include: ['*.jar'])
provided 'javax.annotation:jsr250-api:1.0'
// googleCompile fileTree(dir: 'libs/google', include: ['*.jar'])
}

View File

@ -20,9 +20,13 @@
package edu.tsinghua.hotmobi.model;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import java.util.TimeZone;
@ -31,17 +35,43 @@ import edu.tsinghua.hotmobi.HotMobiLogger;
/**
* Created by mariotaku on 15/8/8.
*/
@ParcelablePlease
@JsonObject
public class BaseEvent {
public class BaseEvent implements Parcelable {
public static final Creator<BaseEvent> CREATOR = new Creator<BaseEvent>() {
@Override
public BaseEvent createFromParcel(Parcel in) {
return new BaseEvent(in);
}
@Override
public BaseEvent[] newArray(int size) {
return new BaseEvent[size];
}
};
@ParcelableThisPlease
@JsonField(name = "start_time")
long startTime;
@ParcelableThisPlease
@JsonField(name = "end_time")
long endTime;
@ParcelableThisPlease
@JsonField(name = "time_offset")
long timeOffset;
@ParcelableThisPlease
@JsonField(name = "location")
LatLng location;
public BaseEvent() {
}
protected BaseEvent(Parcel in) {
BaseEventParcelablePlease.readFromParcel(this, in);
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
@ -67,4 +97,14 @@ public class BaseEvent {
public void markEnd() {
setEndTime(System.currentTimeMillis());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
BaseEventParcelablePlease.writeToParcel(this, dest, flags);
}
}

View File

@ -19,16 +19,24 @@
package edu.tsinghua.hotmobi.model;
import android.os.Parcel;
import android.os.Parcelable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
/**
* Created by mariotaku on 15/8/13.
*/
@ParcelablePlease
@JsonObject
public class LatLng {
public class LatLng implements Parcelable {
@ParcelableThisPlease
@JsonField(name = "latitude")
double latitude;
@ParcelableThisPlease
@JsonField(name = "longitude")
double longitude;
@ -36,11 +44,26 @@ public class LatLng {
}
public LatLng(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
protected LatLng(Parcel in) {
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;
}
@ -56,4 +79,14 @@ public class LatLng {
public void setLongitude(double longitude) {
this.longitude = longitude;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
LatLngParcelablePlease.writeToParcel(this, dest, flags);
}
}

View File

@ -20,6 +20,8 @@
package edu.tsinghua.hotmobi.model;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
@ -30,13 +32,47 @@ import edu.tsinghua.hotmobi.TypeMappingUtil;
* Created by mariotaku on 15/8/20.
*/
@JsonObject
public class LinkEvent extends BaseEvent {
public class LinkEvent extends BaseEvent implements Parcelable {
@JsonField(name = "link")
String link;
@JsonField(name = "type")
String type;
public LinkEvent() {
}
protected LinkEvent(Parcel in) {
super(in);
link = in.readString();
type = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(link);
dest.writeString(type);
}
@Override
public int describeContents() {
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;
}

View File

@ -23,6 +23,8 @@ import android.content.Context;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
@ -30,21 +32,29 @@ import org.mariotaku.twidere.model.ParcelableStatus;
/**
* Created by mariotaku on 15/8/7.
*/
@ParcelablePlease
@JsonObject
public class MediaEvent extends BaseEvent {
@ParcelableThisPlease
@JsonField(name = "id")
long id;
@ParcelableThisPlease
@JsonField(name = "user_id")
long userId;
@ParcelableThisPlease
@JsonField(name = "tweet_type", typeConverter = TweetType.TweetTypeConverter.class)
TweetType tweetType;
@ParcelableThisPlease
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
TimelineType timelineType;
@ParcelableThisPlease
@JsonField(name = "preview_url")
String previewUrl;
@ParcelableThisPlease
@JsonField(name = "media_url")
String mediaUrl;
@ParcelableThisPlease
@JsonField(name = "preview_enabled")
boolean previewEnabled;

View File

@ -25,13 +25,17 @@ import android.net.NetworkInfo;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
/**
* Created by mariotaku on 15/8/20.
*/
@ParcelablePlease
@JsonObject
public class NetworkEvent extends BaseEvent {
@ParcelableThisPlease
@JsonField(name = "network_type")
int networkType;

View File

@ -23,15 +23,20 @@ import android.content.Context;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
/**
* Created by mariotaku on 15/8/8.
*/
@ParcelablePlease
@JsonObject
public class RefreshEvent extends BaseEvent {
@ParcelableThisPlease
@JsonField(name = "ids")
long[] ids;
@ParcelableThisPlease
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
TimelineType timelineType;

View File

@ -21,19 +21,45 @@ package edu.tsinghua.hotmobi.model;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Parcel;
import android.os.Parcelable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
/**
* Created by mariotaku on 15/8/8.
*/
@ParcelablePlease
@JsonObject
public class SessionEvent extends BaseEvent {
public class SessionEvent extends BaseEvent implements Parcelable {
public static final Creator<SessionEvent> CREATOR = new Creator<SessionEvent>() {
@Override
public SessionEvent createFromParcel(Parcel in) {
return new SessionEvent(in);
}
@Override
public SessionEvent[] newArray(int size) {
return new SessionEvent[size];
}
};
@ParcelableThisPlease
@JsonField(name = "configuration")
String configuration;
protected SessionEvent(Parcel in) {
super(in);
SessionEventParcelablePlease.readFromParcel(this, in);
}
public SessionEvent() {
}
public static SessionEvent create(Context context) {
final SessionEvent event = new SessionEvent();
@ -44,6 +70,17 @@ public class SessionEvent extends BaseEvent {
return event;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
SessionEventParcelablePlease.writeToParcel(this, dest, flags);
}
@Override
public int describeContents() {
return 0;
}
public void setConfiguration(String configuration) {
this.configuration = configuration;
}

View File

@ -24,25 +24,34 @@ import android.content.Context;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import org.mariotaku.twidere.model.ParcelableStatus;
/**
* Created by mariotaku on 15/8/7.
*/
@ParcelablePlease
@JsonObject
public class TweetEvent extends BaseEvent {
@ParcelableThisPlease
@JsonField(name = "id")
long id;
@ParcelableThisPlease
@JsonField(name = "account_id")
long accountId;
@ParcelableThisPlease
@JsonField(name = "user_id")
long userId;
@ParcelableThisPlease
@JsonField(name = "tweet_type", typeConverter = TweetType.TweetTypeConverter.class)
TweetType tweetType;
@ParcelableThisPlease
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
TimelineType timelineType;
@ParcelableThisPlease
@JsonField(name = "action", typeConverter = Action.TweetActionConverter.class)
Action action;

View File

@ -32,14 +32,19 @@ 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.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.dagger.component.DaggerBaseAppCompatActivityComponent;
import org.mariotaku.twidere.view.iface.IExtendedView.OnFitSystemWindowsListener;
import java.util.ArrayList;
import javax.inject.Inject;
@SuppressLint("Registered")
public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Constants,
OnFitSystemWindowsListener, SystemWindowsInsetsCallback, IControlBarActivity,
@ -47,6 +52,12 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
// Utility classes
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
@Inject
protected ActivityStack mActivityStack;
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Inject
protected ReadStateManager mReadStateManager;
// Registered listeners
private ArrayList<ControlBarOffsetListener> mControlBarOffsetListeners = new ArrayList<>();
@ -77,10 +88,6 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
return (TwidereApplication) getApplication();
}
public AsyncTwitterWrapper getTwitterWrapper() {
return getTwidereApplication() != null ? getTwidereApplication().getTwitterWrapper() : null;
}
public boolean isVisible() {
return mIsVisible;
}
@ -142,6 +149,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DaggerBaseAppCompatActivityComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
mKeyboardShortcutsHandler = TwidereApplication.getInstance(this).getKeyboardShortcutsHandler();
}
@ -149,6 +157,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
@Override
protected void onStart() {
super.onStart();
mActivityStack.dispatchStart(this);
mIsVisible = true;
}
@ -177,6 +186,7 @@ public class BaseAppCompatActivity extends ThemedAppCompatActivity implements Co
@Override
protected void onStop() {
mIsVisible = false;
mActivityStack.dispatchStop(this);
super.onStop();
}

View File

@ -115,7 +115,6 @@ import org.mariotaku.twidere.preference.ServicePickerPreference;
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
import org.mariotaku.twidere.text.MarkForDeleteSpan;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ContentValuesCreator;
import org.mariotaku.twidere.util.EditTextEnterHandler;
import org.mariotaku.twidere.util.EditTextEnterHandler.EnterListener;
@ -163,7 +162,6 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
// Utility classes
private final Extractor mExtractor = new Extractor();
private TwidereValidator mValidator;
private AsyncTwitterWrapper mTwitterWrapper;
private LocationManager mLocationManager;
private SharedPreferencesWrapper mPreferences;
private ContentResolver mResolver;
@ -589,7 +587,6 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
Context.MODE_PRIVATE, SharedPreferenceConstants.class);
final TwidereApplication app = TwidereApplication.getInstance(this);
mTwitterWrapper = app.getTwitterWrapper();
mResolver = getContentResolver();
mValidator = new TwidereValidator(this);
mImageLoader = app.getMediaLoaderWrapper();

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.activity.support;
import android.app.ActivityManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.SearchManager;
@ -85,7 +86,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Mentions;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.service.StreamingService;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.CustomTabUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
@ -128,6 +128,7 @@ import static org.mariotaku.twidere.util.Utils.showMenuItemToast;
public class HomeActivity extends BaseAppCompatActivity implements OnClickListener, OnPageChangeListener,
SupportFragmentCallback, OnLongClickListener {
private static final String EXTRA_SESSION_EVENT = "session_event";
private final Handler mHandler = new Handler();
private final ContentObserver mAccountChangeObserver = new AccountChangeObserver(this, mHandler);
@ -136,12 +137,10 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
private SharedPreferences mPreferences;
private AsyncTwitterWrapper mTwitterWrapper;
private NotificationManager mNotificationManager;
private MultiSelectEventHandler mMultiSelectHandler;
private ReadStateManager mReadStateManager;
private SupportTabsAdapter mPagerAdapter;
@ -355,9 +354,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
return;
}
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mTwitterWrapper = getTwitterWrapper();
final TwidereApplication app = TwidereApplication.getInstance(this);
mReadStateManager = app.getReadStateManager();
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mMultiSelectHandler = new MultiSelectEventHandler(this);
mMultiSelectHandler.dispatchOnCreate();
@ -431,6 +428,10 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (Utils.isStreamingEnabled()) {
startService(new Intent(this, StreamingService.class));
}
if (savedInstanceState != null) {
mSessionEvent = savedInstanceState.getParcelable(EXTRA_SESSION_EVENT);
}
}
@Override
@ -444,8 +445,9 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
assert bus != null;
bus.register(this);
// BEGIN HotMobi
final SessionEvent event = SessionEvent.create(this);
mSessionEvent = event;
if (mSessionEvent == null) {
mSessionEvent = SessionEvent.create(this);
}
// END HotMobi
mReadStateManager.registerOnSharedPreferenceChangeListener(mReadStateChangeListener);
updateUnreadCount();
@ -481,8 +483,11 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
// BEGIN HotMobi
final SessionEvent event = mSessionEvent;
event.markEnd();
HotMobiLogger.getInstance(this).log(event);
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
if (event != null && isFinishing()) {
event.markEnd();
HotMobiLogger.getInstance(this).log(event);
}
// END HotMobi
super.onStop();
}
@ -494,6 +499,12 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
public void notifyAccountsChanged() {
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(EXTRA_SESSION_EVENT, mSessionEvent);
}
@Subscribe
public void notifyTaskStateChanged(TaskStateChangedEvent event) {
updateActionsButton();

View File

@ -35,19 +35,25 @@ 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.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.StrictModeUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.ThemedLayoutInflaterFactory;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.component.DaggerThemedFragmentActivityComponent;
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
import javax.inject.Inject;
public abstract class ThemedFragmentActivity extends FragmentActivity implements Constants,
IThemedActivity, KeyboardShortcutCallback {
// Utility classes
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
// Data fields
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
@ -129,6 +135,7 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
StrictModeUtils.detectAllThreadPolicy();
}
super.onCreate(savedInstanceState);
DaggerThemedFragmentActivityComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
mKeyboardShortcutsHandler = TwidereApplication.getInstance(this).getKeyboardShortcutsHandler();
}

View File

@ -56,6 +56,8 @@ import org.mariotaku.twidere.view.holder.StatusViewHolder;
import org.mariotaku.twidere.view.holder.StatusViewHolder.DummyStatusHolderAdapter;
import org.mariotaku.twidere.view.holder.StatusViewHolder.StatusClickListener;
import javax.inject.Inject;
/**
* Created by mariotaku on 15/1/3.
*/
@ -72,7 +74,6 @@ public abstract class AbsActivitiesAdapter<Data> extends LoadMoreSupportAdapter<
private final LayoutInflater mInflater;
private final MediaLoaderWrapper mImageLoader;
private final MediaLoadingHandler mLoadingHandler;
private final AsyncTwitterWrapper mTwitterWrapper;
private final int mCardBackgroundColor;
private final int mTextSize;
private final int mProfileImageStyle, mMediaPreviewStyle, mLinkHighlightingStyle;
@ -86,13 +87,13 @@ public abstract class AbsActivitiesAdapter<Data> extends LoadMoreSupportAdapter<
private ActivityAdapterListener mActivityAdapterListener;
protected AbsActivitiesAdapter(final Context context, boolean compact) {
super(context);
mContext = context;
final TwidereApplication app = TwidereApplication.getInstance(context);
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
mInflater = LayoutInflater.from(context);
mImageLoader = app.getMediaLoaderWrapper();
mLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
mTwitterWrapper = app.getTwitterWrapper();
mUserColorNameManager = app.getUserColorNameManager();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);

View File

@ -30,6 +30,8 @@ import org.mariotaku.twidere.view.holder.GapViewHolder;
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
import org.mariotaku.twidere.view.holder.StatusViewHolder;
import javax.inject.Inject;
/**
* Created by mariotaku on 14/11/19.
*/
@ -42,7 +44,6 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
private final LayoutInflater mInflater;
private final MediaLoaderWrapper mMediaLoader;
private final MediaLoadingHandler mLoadingHandler;
private final AsyncTwitterWrapper mTwitterWrapper;
private final TwidereLinkify mLinkify;
private final UserColorNameManager mUserColorNameManager;
@ -68,6 +69,7 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
private boolean mShowAccountsColor;
public AbsStatusesAdapter(Context context, boolean compact) {
super(context);
mContext = context;
final TwidereApplication app = TwidereApplication.getInstance(context);
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
@ -75,7 +77,6 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
mMediaLoader = app.getMediaLoaderWrapper();
mUserColorNameManager = app.getUserColorNameManager();
mLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
mTwitterWrapper = app.getTwitterWrapper();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));

View File

@ -40,6 +40,8 @@ import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
import org.mariotaku.twidere.view.holder.UserListViewHolder;
import javax.inject.Inject;
public abstract class AbsUserListsAdapter<D> extends LoadMoreSupportAdapter<ViewHolder> implements Constants,
IUserListsAdapter<D> {
@ -53,20 +55,19 @@ public abstract class AbsUserListsAdapter<D> extends LoadMoreSupportAdapter<View
private final boolean mCompactCards;
private final int mProfileImageStyle;
private final int mTextSize;
private final AsyncTwitterWrapper mTwitterWrapper;
private final boolean mDisplayProfileImage;
private final UserColorNameManager mUserColorNameManager;
private final boolean mNameFirst;
public AbsUserListsAdapter(final Context context, final boolean compact) {
super(context);
final TwidereApplication app = TwidereApplication.getInstance(context);
mContext = context;
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
mInflater = LayoutInflater.from(context);
mMediaLoader = app.getMediaLoaderWrapper();
mUserColorNameManager = app.getUserColorNameManager();
mTwitterWrapper = app.getTwitterWrapper();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));

View File

@ -40,6 +40,8 @@ import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
import org.mariotaku.twidere.view.holder.UserViewHolder;
import javax.inject.Inject;
public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHolder> implements Constants,
IUsersAdapter<D> {
@ -53,19 +55,18 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
private final boolean mCompactCards;
private final int mProfileImageStyle;
private final int mTextSize;
private final AsyncTwitterWrapper mTwitterWrapper;
private final boolean mDisplayProfileImage;
private final UserColorNameManager mUserColorNameManager;
public AbsUsersAdapter(final Context context, final boolean compact) {
super(context);
final TwidereApplication app = TwidereApplication.getInstance(context);
mContext = context;
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
mInflater = LayoutInflater.from(context);
mMediaLoader = app.getMediaLoaderWrapper();
mUserColorNameManager = app.getUserColorNameManager();
mTwitterWrapper = app.getTwitterWrapper();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));

View File

@ -0,0 +1,48 @@
/*
* 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.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.dagger.component.DaggerBaseAdapterComponent;
import javax.inject.Inject;
/**
* Created by mariotaku on 15/10/5.
*/
public abstract class BaseAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Inject
protected ReadStateManager mReadStateManager;
public BaseAdapter(Context context) {
//noinspection unchecked
DaggerBaseAdapterComponent.builder()
.applicationModule(TwidereApplication.getModule(context))
.build()
.inject((BaseAdapter<RecyclerView.ViewHolder>) this);
}
}

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
@ -27,12 +28,16 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter;
/**
* Created by mariotaku on 15/4/16.
*/
public abstract class LoadMoreSupportAdapter<VH extends ViewHolder> extends Adapter<VH>
public abstract class LoadMoreSupportAdapter<VH extends ViewHolder> extends BaseAdapter<VH>
implements ILoadMoreSupportAdapter {
private boolean mLoadMoreSupported;
private boolean mLoadMoreIndicatorVisible;
public LoadMoreSupportAdapter(Context context) {
super(context);
}
@Override
public final boolean isLoadMoreIndicatorVisible() {
return mLoadMoreIndicatorVisible;

View File

@ -24,7 +24,6 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
@ -48,6 +47,8 @@ import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
import org.mariotaku.twidere.view.holder.MessageEntryViewHolder;
import javax.inject.Inject;
public class MessageEntriesAdapter extends LoadMoreSupportAdapter<ViewHolder> implements Constants,
IContentCardAdapter, OnClickListener, OnReadStateChangeListener {
@ -61,10 +62,8 @@ public class MessageEntriesAdapter extends LoadMoreSupportAdapter<ViewHolder> im
private final int mTextSize;
private final int mProfileImageStyle;
private final int mMediaPreviewStyle;
private final ReadStateManager mReadStateManager;
private final OnSharedPreferenceChangeListener mReadStateChangeListener;
private UserColorNameManager mUserColorNameManager;
private final AsyncTwitterWrapper mTwitterWrapper;
private final boolean mDisplayProfileImage;
private boolean mShowAccountsColor;
@ -73,19 +72,18 @@ public class MessageEntriesAdapter extends LoadMoreSupportAdapter<ViewHolder> im
private StringLongPair[] mPositionPairs;
public MessageEntriesAdapter(final Context context) {
super(context);
mContext = context;
mInflater = LayoutInflater.from(context);
final TwidereApplication app = TwidereApplication.getInstance(context);
mMultiSelectManager = app.getMultiSelectManager();
mImageLoader = app.getMediaLoaderWrapper();
mTwitterWrapper = app.getTwitterWrapper();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mProfileImageStyle = Utils.getProfileImageStyle(preferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
mMediaPreviewStyle = Utils.getMediaPreviewStyle(preferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
mDisplayProfileImage = preferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));
mReadStateManager = app.getReadStateManager();
mUserColorNameManager = app.getUserColorNameManager();
mReadStateChangeListener = new OnSharedPreferenceChangeListener() {

View File

@ -53,19 +53,18 @@ import org.mariotaku.twidere.activity.MainHondaJOJOActivity;
import org.mariotaku.twidere.service.RefreshService;
import org.mariotaku.twidere.util.AbsLogger;
import org.mariotaku.twidere.util.AsyncTaskManager;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.DebugModeUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.MathUtils;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.StrictModeUtils;
import org.mariotaku.twidere.util.TwidereLogger;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.VideoLoader;
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import org.mariotaku.twidere.util.imageloader.ReadOnlyDiskLRUNameCache;
import org.mariotaku.twidere.util.imageloader.TwidereImageDownloader;
import org.mariotaku.twidere.util.imageloader.URLFileNameGenerator;
@ -95,7 +94,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
private ImageLoader mImageLoader;
private AsyncTaskManager mAsyncTaskManager;
private SharedPreferences mPreferences;
private AsyncTwitterWrapper mTwitterWrapper;
private MultiSelectManager mMultiSelectManager;
private TwidereImageDownloader mImageDownloader, mFullImageDownloader;
private DiskCache mDiskCache, mFullDiskCache;
@ -104,11 +102,11 @@ public class TwidereApplication extends MultiDexApplication implements Constants
private SQLiteDatabase mDatabase;
private Bus mMessageBus;
private VideoLoader mVideoLoader;
private ReadStateManager mReadStateManager;
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
private UserColorNameManager mUserColorNameManager;
private HotMobiLogger mHotMobiLogger;
private ApplicationModule mApplicationModule;
@NonNull
public static TwidereApplication getInstance(@NonNull final Context context) {
@ -149,11 +147,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
return mNetwork = new TwidereHostAddressResolver(this);
}
public ReadStateManager getReadStateManager() {
if (mReadStateManager != null) return mReadStateManager;
return mReadStateManager = new ReadStateManager(this);
}
public KeyboardShortcutsHandler getKeyboardShortcutsHandler() {
if (mKeyboardShortcutsHandler != null) return mKeyboardShortcutsHandler;
mKeyboardShortcutsHandler = new KeyboardShortcutsHandler(this);
@ -217,11 +210,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
return mSQLiteOpenHelper = new TwidereSQLiteOpenHelper(this, DATABASES_NAME, DATABASES_VERSION);
}
public AsyncTwitterWrapper getTwitterWrapper() {
if (mTwitterWrapper != null) return mTwitterWrapper;
return mTwitterWrapper = new AsyncTwitterWrapper(this);
}
@Override
public void onCreate() {
if (BuildConfig.DEBUG) {
@ -267,7 +255,9 @@ public class TwidereApplication extends MultiDexApplication implements Constants
private void initBugReport() {
final SharedPreferences preferences = getSharedPreferences();
if (!preferences.getBoolean(KEY_BUG_REPORTS, true)) return;
AbsLogger.setImplementation(new TwidereLogger());
if (!BuildConfig.DEBUG) {
AbsLogger.setImplementation(new TwidereLogger());
}
AbsLogger.init(this);
}
@ -355,4 +345,13 @@ public class TwidereApplication extends MultiDexApplication implements Constants
if (mHotMobiLogger != null) return mHotMobiLogger;
return mHotMobiLogger = new HotMobiLogger(this);
}
public static ApplicationModule getModule(Context context) {
return getInstance(context).getApplicationModule();
}
private ApplicationModule getApplicationModule() {
if (mApplicationModule != null) return mApplicationModule;
return mApplicationModule = new ApplicationModule(this);
}
}

View File

@ -23,6 +23,7 @@ import android.app.Activity;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
@ -31,9 +32,21 @@ import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
import javax.inject.Inject;
public class BaseFragment extends Fragment implements Constants {
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Override
public void onAttach(Context context) {
super.onAttach(context);
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
}
public TwidereApplication getApplication() {
final Activity activity = getActivity();
if (activity != null) return (TwidereApplication) activity.getApplication();
@ -63,11 +76,6 @@ public class BaseFragment extends Fragment implements Constants {
return null;
}
public AsyncTwitterWrapper getTwitterWrapper() {
final TwidereApplication app = getApplication();
return app != null ? app.getTwitterWrapper() : null;
}
public void registerReceiver(final BroadcastReceiver receiver, final IntentFilter filter) {
final Activity activity = getActivity();
if (activity == null) return;

View File

@ -23,6 +23,7 @@ import android.app.Activity;
import android.app.ListFragment;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -36,6 +37,9 @@ import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.component.DaggerBaseListFragmentComponent;
import javax.inject.Inject;
public class BaseListFragment extends ListFragment implements Constants, OnScrollListener, RefreshScrollTopInterface {
@ -44,6 +48,7 @@ public class BaseListFragment extends ListFragment implements Constants, OnScrol
private boolean mReachedBottom, mNotReachedBottomBefore = true;
public final TwidereApplication getApplication() {
return TwidereApplication.getInstance(getActivity());
}
@ -75,10 +80,6 @@ public class BaseListFragment extends ListFragment implements Constants, OnScrol
return args != null ? args.getInt(EXTRA_TAB_POSITION, -1) : -1;
}
public AsyncTwitterWrapper getTwitterWrapper() {
return getApplication().getTwitterWrapper();
}
public void invalidateOptionsMenu() {
final Activity activity = getActivity();
if (activity == null) return;
@ -105,9 +106,13 @@ public class BaseListFragment extends ListFragment implements Constants, OnScrol
lv.setOnScrollListener(this);
}
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
public void onAttach(Context context) {
super.onAttach(context);
DaggerBaseListFragmentComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
}
@Override

View File

@ -147,7 +147,7 @@ public abstract class AbsActivitiesFragment<Data> extends AbsContentRecyclerView
public boolean scrollToStart() {
final boolean result = super.scrollToStart();
if (result) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final int tabPosition = getTabPosition();
if (twitter != null && tabPosition != -1) {
twitter.clearUnreadCountAsync(tabPosition);

View File

@ -107,7 +107,6 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
};
private SharedPreferences mPreferences;
private PopupMenu mPopupMenu;
private ReadStateManager mReadStateManager;
private final OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
@ -130,7 +129,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
return true;
}
return Utils.handleMenuItemClick(getActivity(), AbsStatusesFragment.this,
getFragmentManager(), getTwitterWrapper(), status, item);
getFragmentManager(), mTwitterWrapper, status, item);
}
};
private OnScrollListener mPauseOnScrollListener;
@ -187,7 +186,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
return true;
}
case ACTION_STATUS_FAVORITE: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_id, status.id);
} else {
@ -348,7 +347,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
break;
}
case R.id.favorite_count: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_id, status.id);
@ -466,7 +465,6 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mReadStateManager = getReadStateManager();
final AbsStatusesAdapter<Data> adapter = getAdapter();
final RecyclerView recyclerView = getRecyclerView();
final LinearLayoutManager layoutManager = getLayoutManager();

View File

@ -52,7 +52,7 @@ public class AddUserListMemberDialogFragment extends BaseSupportDialogFragment i
switch (which) {
case DialogInterface.BUTTON_POSITIVE: {
final String mText = ParseUtils.parseString(mEditText.getText());
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (mText == null || mText.length() <= 0 || twitter == null) return;
twitter.addUserListMembersAsync(args.getLong(EXTRA_ACCOUNT_ID), args.getLong(EXTRA_LIST_ID));
break;

View File

@ -22,6 +22,7 @@ package org.mariotaku.twidere.fragment.support;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.support.v4.app.DialogFragment;
@ -29,6 +30,9 @@ import android.support.v4.app.DialogFragment;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.dagger.component.DaggerBaseSupportDialogFragmentComponent;
import javax.inject.Inject;
public class BaseSupportDialogFragment extends DialogFragment implements Constants {
@ -60,9 +64,13 @@ public class BaseSupportDialogFragment extends DialogFragment implements Constan
return null;
}
public AsyncTwitterWrapper getTwitterWrapper() {
final TwidereApplication app = getApplication();
return app != null ? app.getTwitterWrapper() : null;
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Override
public void onAttach(Context context) {
super.onAttach(context);
DaggerBaseSupportDialogFragmentComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
}
public void registerReceiver(final BroadcastReceiver receiver, final IntentFilter filter) {

View File

@ -45,9 +45,21 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.ThemedLayoutInflaterFactory;
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
import javax.inject.Inject;
public class BaseSupportFragment extends Fragment implements IBaseFragment, Constants {
@Inject
protected AsyncTwitterWrapper mTwitterWrapper;
@Inject
protected ReadStateManager mReadStateManager;
public BaseSupportFragment() {
}
@Override
public final void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@ -55,10 +67,13 @@ public class BaseSupportFragment extends Fragment implements IBaseFragment, Cons
requestFitSystemWindows();
}
public BaseSupportFragment() {
@Override
public void onAttach(Context context) {
super.onAttach(context);
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
}
public TwidereApplication getApplication() {
final Activity activity = getActivity();
if (activity != null) return (TwidereApplication) activity.getApplication();
@ -87,13 +102,6 @@ public class BaseSupportFragment extends Fragment implements IBaseFragment, Cons
return null;
}
public AsyncTwitterWrapper getTwitterWrapper() {
return getApplication() != null ? getApplication().getTwitterWrapper() : null;
}
public ReadStateManager getReadStateManager() {
return getApplication() != null ? getApplication().getReadStateManager() : null;
}
public void invalidateOptionsMenu() {
final FragmentActivity activity = getActivity();

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@ -27,6 +26,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
@ -45,7 +45,7 @@ public class CreateUserBlockDialogFragment extends BaseSupportDialogFragment imp
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUser user = getUser();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user == null || twitter == null) return;
twitter.createBlockAsync(user.account_id, user.id);
break;

View File

@ -19,12 +19,12 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
@ -33,7 +33,6 @@ import com.rengwuxian.materialedittext.MaterialEditText;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.text.validator.UserListNameValidator;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.ThemeUtils;
@ -45,7 +44,6 @@ public class CreateUserListDialogFragment extends BaseSupportDialogFragment impl
private long mAccountId;
private long mListId;
private boolean mIsPublic = true;
private AsyncTwitterWrapper mTwitterWrapper;
@Override
public void onClick(final DialogInterface dialog, final int which) {
@ -66,7 +64,6 @@ public class CreateUserListDialogFragment extends BaseSupportDialogFragment impl
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
mTwitterWrapper = getApplication().getTwitterWrapper();
final Bundle bundle = savedInstanceState == null ? getArguments() : savedInstanceState;
mAccountId = bundle != null ? bundle.getLong(EXTRA_ACCOUNT_ID, -1) : -1;
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@ -27,6 +26,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
@ -45,7 +45,7 @@ public class CreateUserMuteDialogFragment extends BaseSupportDialogFragment impl
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUser user = getUser();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user == null || twitter == null) return;
twitter.createMuteAsync(user.account_id, user.id);
break;

View File

@ -50,7 +50,7 @@ public class DeleteUserListMembersDialogFragment extends BaseSupportDialogFragme
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUser[] users = getUsers();
final ParcelableUserList userList = getUserList();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (users == null || userList == null || twitter == null) return;
twitter.deleteUserListMembersAsync(userList.account_id, userList.id, users);
break;

View File

@ -46,7 +46,7 @@ public class DestroyFriendshipDialogFragment extends BaseSupportDialogFragment i
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUser user = getUser();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user == null || twitter == null) return;
twitter.destroyFriendshipAsync(user.account_id, user.id);
break;

View File

@ -19,80 +19,80 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
public class DestroySavedSearchDialogFragment extends BaseSupportDialogFragment implements
DialogInterface.OnClickListener {
DialogInterface.OnClickListener {
public static final String FRAGMENT_TAG = "destroy_saved_search";
public static final String FRAGMENT_TAG = "destroy_saved_search";
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final long accountId = getAccountId();
final int searchId = getSearchId();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
if (searchId <= 0 || twitter == null) return;
twitter.destroySavedSearchAsync(accountId, searchId);
break;
default:
break;
}
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final String name = getSearchName();
if (name != null) {
builder.setTitle(getString(R.string.destroy_saved_search, name));
builder.setMessage(getString(R.string.destroy_saved_search_confirm_message, name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final long accountId = getAccountId();
final int searchId = getSearchId();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (searchId <= 0 || twitter == null) return;
twitter.destroySavedSearchAsync(accountId, searchId);
break;
default:
break;
}
}
private long getAccountId() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_ACCOUNT_ID)) return -1;
return args.getLong(EXTRA_ACCOUNT_ID);
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final String name = getSearchName();
if (name != null) {
builder.setTitle(getString(R.string.destroy_saved_search, name));
builder.setMessage(getString(R.string.destroy_saved_search_confirm_message, name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
private int getSearchId() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_SEARCH_ID)) return -1;
return args.getInt(EXTRA_SEARCH_ID);
}
private long getAccountId() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_ACCOUNT_ID)) return -1;
return args.getLong(EXTRA_ACCOUNT_ID);
}
private String getSearchName() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_NAME)) return null;
return args.getString(EXTRA_NAME);
}
private int getSearchId() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_SEARCH_ID)) return -1;
return args.getInt(EXTRA_SEARCH_ID);
}
public static DestroySavedSearchDialogFragment show(final FragmentManager fm, final long accountId,
final int searchId, final String name) {
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, accountId);
args.putInt(EXTRA_SEARCH_ID, searchId);
args.putString(EXTRA_NAME, name);
final DestroySavedSearchDialogFragment f = new DestroySavedSearchDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
private String getSearchName() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_NAME)) return null;
return args.getString(EXTRA_NAME);
}
public static DestroySavedSearchDialogFragment show(final FragmentManager fm, final long accountId,
final int searchId, final String name) {
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, accountId);
args.putInt(EXTRA_SEARCH_ID, searchId);
args.putString(EXTRA_NAME, name);
final DestroySavedSearchDialogFragment f = new DestroySavedSearchDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
}

View File

@ -19,13 +19,13 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.ParcelableStatus;
@ -34,46 +34,46 @@ import org.mariotaku.twidere.util.ThemeUtils;
public class DestroyStatusDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
public static final String FRAGMENT_TAG = "destroy_status";
public static final String FRAGMENT_TAG = "destroy_status";
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableStatus status = getStatus();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
if (status == null || twitter == null) return;
twitter.destroyStatusAsync(status.account_id, status.id);
break;
default:
break;
}
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
builder.setTitle(R.string.destroy_status);
builder.setMessage(R.string.destroy_status_confirm_message);
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableStatus status = getStatus();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (status == null || twitter == null) return;
twitter.destroyStatusAsync(status.account_id, status.id);
break;
default:
break;
}
}
private ParcelableStatus getStatus() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_STATUS)) return null;
return args.getParcelable(EXTRA_STATUS);
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
builder.setTitle(R.string.destroy_status);
builder.setMessage(R.string.destroy_status_confirm_message);
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public static DestroyStatusDialogFragment show(final FragmentManager fm, final ParcelableStatus status) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_STATUS, status);
final DestroyStatusDialogFragment f = new DestroyStatusDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
private ParcelableStatus getStatus() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_STATUS)) return null;
return args.getParcelable(EXTRA_STATUS);
}
public static DestroyStatusDialogFragment show(final FragmentManager fm, final ParcelableStatus status) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_STATUS, status);
final DestroyStatusDialogFragment f = new DestroyStatusDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
}

View File

@ -19,13 +19,13 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.ParcelableUserList;
@ -34,49 +34,49 @@ import org.mariotaku.twidere.util.ThemeUtils;
public class DestroyUserListDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
public static final String FRAGMENT_TAG = "destroy_user_list";
public static final String FRAGMENT_TAG = "destroy_user_list";
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUserList user_list = getUserList();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
if (user_list == null || twitter == null) return;
twitter.destroyUserListAsync(user_list.account_id, user_list.id);
break;
default:
break;
}
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final ParcelableUserList userList = getUserList();
if (userList != null) {
builder.setTitle(getString(R.string.delete_user_list, userList.name));
builder.setMessage(getString(R.string.delete_user_list_confirm_message, userList.name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUserList user_list = getUserList();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user_list == null || twitter == null) return;
twitter.destroyUserListAsync(user_list.account_id, user_list.id);
break;
default:
break;
}
}
private ParcelableUserList getUserList() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_USER_LIST)) return null;
return args.getParcelable(EXTRA_USER_LIST);
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final ParcelableUserList userList = getUserList();
if (userList != null) {
builder.setTitle(getString(R.string.delete_user_list, userList.name));
builder.setMessage(getString(R.string.delete_user_list_confirm_message, userList.name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public static DestroyUserListDialogFragment show(final FragmentManager fm, final ParcelableUserList user_list) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_USER_LIST, user_list);
final DestroyUserListDialogFragment f = new DestroyUserListDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
private ParcelableUserList getUserList() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_USER_LIST)) return null;
return args.getParcelable(EXTRA_USER_LIST);
}
public static DestroyUserListDialogFragment show(final FragmentManager fm, final ParcelableUserList user_list) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_USER_LIST, user_list);
final DestroyUserListDialogFragment f = new DestroyUserListDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
}

View File

@ -19,13 +19,13 @@
package org.mariotaku.twidere.fragment.support;
import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.ParcelableUserList;
@ -33,52 +33,52 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
public class DestroyUserListSubscriptionDialogFragment extends BaseSupportDialogFragment implements
DialogInterface.OnClickListener {
DialogInterface.OnClickListener {
public static final String FRAGMENT_TAG = "destroy_user_list";
public static final String FRAGMENT_TAG = "destroy_user_list";
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUserList user_list = getUserList();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
if (user_list == null || twitter == null) return;
twitter.destroyUserListSubscriptionAsync(user_list.account_id, user_list.id);
break;
default:
break;
}
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final ParcelableUserList userList = getUserList();
if (userList != null) {
builder.setTitle(getString(R.string.unsubscribe_from_user_list, userList.name));
builder.setMessage(getString(R.string.unsubscribe_from_user_list_confirm_message, userList.name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUserList user_list = getUserList();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user_list == null || twitter == null) return;
twitter.destroyUserListSubscriptionAsync(user_list.account_id, user_list.id);
break;
default:
break;
}
}
private ParcelableUserList getUserList() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_USER_LIST)) return null;
return args.getParcelable(EXTRA_USER_LIST);
}
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
final ParcelableUserList userList = getUserList();
if (userList != null) {
builder.setTitle(getString(R.string.unsubscribe_from_user_list, userList.name));
builder.setMessage(getString(R.string.unsubscribe_from_user_list_confirm_message, userList.name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
public static DestroyUserListSubscriptionDialogFragment show(final FragmentManager fm,
final ParcelableUserList userList) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_USER_LIST, userList);
final DestroyUserListSubscriptionDialogFragment f = new DestroyUserListSubscriptionDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
private ParcelableUserList getUserList() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_USER_LIST)) return null;
return args.getParcelable(EXTRA_USER_LIST);
}
public static DestroyUserListSubscriptionDialogFragment show(final FragmentManager fm,
final ParcelableUserList userList) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_USER_LIST, userList);
final DestroyUserListSubscriptionDialogFragment f = new DestroyUserListSubscriptionDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
}

View File

@ -111,7 +111,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
@Override
public boolean isRefreshing() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
return twitter != null && (twitter.isReceivedDirectMessagesRefreshing() || twitter.isSentDirectMessagesRefreshing());
}
@ -209,7 +209,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
public boolean scrollToStart() {
final boolean result = super.scrollToStart();
if (result) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final int tabPosition = getTabPosition();
if (twitter != null && tabPosition >= 0) {
twitter.clearUnreadCountAsync(tabPosition);
@ -232,7 +232,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
@Override
protected void onPostExecute(final long[][] result) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
twitter.getReceivedDirectMessagesAsync(result[0], null, result[1]);
twitter.getSentDirectMessagesAsync(result[0], null, null);
@ -333,7 +333,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
}
protected void updateRefreshState() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
setRefreshing(twitter != null && (twitter.isReceivedDirectMessagesRefreshing() || twitter.isSentDirectMessagesRefreshing()));
}
@ -372,7 +372,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
@Override
protected void onPostExecute(final long[][] result) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
twitter.getReceivedDirectMessagesAsync(result[0], result[1], null);
twitter.getSentDirectMessagesAsync(result[0], result[2], null);
@ -411,7 +411,7 @@ public class DirectMessagesFragment extends AbsContentRecyclerViewFragment<Messa
@Override
protected void onPostExecute(final Object result) {
final AsyncTwitterWrapper twitter = fragment.getTwitterWrapper();
final AsyncTwitterWrapper twitter = fragment.mTwitterWrapper;
if (twitter != null) {
twitter.removeUnreadCountsAsync(fragment.getTabPosition(), fragment.getUnreadCountsToRemove());
}

View File

@ -207,7 +207,7 @@ public class DraftsFragment extends BaseSupportFragment implements Constants, Lo
@Override
public void onStart() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter != null) {
twitter.clearNotificationAsync(NOTIFICATION_ID_DRAFTS);
}
@ -257,7 +257,7 @@ public class DraftsFragment extends BaseSupportFragment implements Constants, Lo
}
private boolean sendDrafts(final List<DraftItem> list) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return false;
for (final DraftItem item : list) {
if (item.action_type == Drafts.ACTION_UPDATE_STATUS || item.action_type <= 0) {

View File

@ -49,20 +49,20 @@ public class HomeTimelineFragment extends CursorStatusesFragment {
@Override
protected void updateRefreshState() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
setRefreshing(twitter.isHomeTimelineRefreshing());
}
@Override
public boolean isRefreshing() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
return twitter != null && twitter.isHomeTimelineRefreshing();
}
@Override
public boolean getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return false;
if (maxIds == null) return twitter.refreshAll(accountIds);
return twitter.getHomeTimelineAsync(accountIds, maxIds, sinceIds);

View File

@ -49,7 +49,7 @@ public class MentionsTimelineFragment extends CursorStatusesFragment {
@Override
public boolean isRefreshing() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
return twitter != null && twitter.isMentionsTimelineRefreshing();
}
@ -65,14 +65,14 @@ public class MentionsTimelineFragment extends CursorStatusesFragment {
@Override
protected void updateRefreshState() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
setRefreshing(twitter.isMentionsTimelineRefreshing());
}
@Override
public boolean getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return false;
return twitter.getMentionsTimelineAsync(accountIds, maxIds, sinceIds);
}

View File

@ -165,10 +165,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
// Utility classes
private TwidereValidator mValidator;
private AsyncTwitterWrapper mTwitterWrapper;
private SharedPreferencesWrapper mPreferences;
private SharedPreferences mMessageDrafts;
private ReadStateManager mReadStateManager;
private MediaLoaderWrapper mImageLoader;
private UserColorNameManager mUserColorNameManager;
private EffectViewHelper mEffectHelper;
@ -239,8 +237,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
mUserColorNameManager = UserColorNameManager.getInstance(activity);
mMessageDrafts = getSharedPreferences(MESSAGE_DRAFTS_PREFERENCES_NAME, Context.MODE_PRIVATE);
mImageLoader = TwidereApplication.getInstance(activity).getMediaLoaderWrapper();
mReadStateManager = getReadStateManager();
mTwitterWrapper = getTwitterWrapper();
mValidator = new TwidereValidator(activity);
final View view = getView();
@ -891,13 +887,16 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
return builder.create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE: {
final ParcelableCredentials account = getArguments().getParcelable(EXTRA_ACCOUNT);
final ParcelableUser user = getArguments().getParcelable(EXTRA_USER);
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final Bundle args = getArguments();
final ParcelableCredentials account = args.getParcelable(EXTRA_ACCOUNT);
final ParcelableUser user = args.getParcelable(EXTRA_USER);
if (account == null || user == null) return;
final AsyncTwitterWrapper twitter = mTwitterWrapper;
twitter.destroyMessageConversationAsync(account.account_id, user.id);
break;
}
@ -905,15 +904,15 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
}
}
private static class SetReadStateTask extends AsyncTask<Object, Object, Cursor> {
static class SetReadStateTask extends AsyncTask<Object, Object, Cursor> {
private final Context mContext;
private final ReadStateManager mReadStateManager;
private final ParcelableCredentials mAccount;
private final ParcelableUser mRecipient;
public SetReadStateTask(Context context, ParcelableCredentials account, ParcelableUser recipient) {
mReadStateManager = TwidereApplication.getModule(context).getReadStateManager();
mContext = context;
mReadStateManager = TwidereApplication.getInstance(context).getReadStateManager();
mAccount = account;
mRecipient = recipient;
}

View File

@ -45,7 +45,7 @@ public class ReportSpamDialogFragment extends BaseSupportDialogFragment implemen
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final ParcelableUser user = getUser();
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (user == null || twitter == null) return;
twitter.reportSpamAsync(user.account_id, user.id);
break;

View File

@ -38,6 +38,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
@ -51,6 +52,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereValidator;
import org.mariotaku.twidere.view.ComposeMaterialEditText;
import org.mariotaku.twidere.view.StatusTextCountView;
import org.mariotaku.twidere.view.holder.StatusViewHolder;
import org.mariotaku.twidere.view.holder.StatusViewHolder.DummyStatusHolderAdapter;
@ -60,9 +62,7 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
Constants, DialogInterface.OnClickListener {
public static final String FRAGMENT_TAG = "retweet_quote";
private ComposeMaterialEditText mEditComment;
private PopupMenu mPopupMenu;
private View mCommentMenu;
private TwidereValidator mValidator;
private SharedPreferencesWrapper mPreferences;
@ -72,7 +72,7 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
if (status == null) return;
switch (which) {
case DialogInterface.BUTTON_POSITIVE: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
retweetOrQuote(twitter, status);
break;
@ -124,24 +124,14 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
view.findViewById(R.id.item_content).setFocusable(false);
view.findViewById(R.id.comment_container).setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
mEditComment = (ComposeMaterialEditText) view.findViewById(R.id.edit_comment);
final ComposeMaterialEditText mEditComment = (ComposeMaterialEditText) view.findViewById(R.id.edit_comment);
mEditComment.setAccountId(status.account_id);
// mEditComment.setLengthChecker(new METLengthChecker() {
//
// final String statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.quote_id).toString();
//
// @Override
// public int getLength(CharSequence text) {
// return mValidator.getTweetLength(text + " " + statusLink);
// }
// });
// mEditComment.setMaxCharacters(mValidator.getMaxTweetLength());
final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(mEditComment, new EditTextEnterHandler.EnterListener() {
@Override
public void onHitEnter() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableStatus status = getStatus();
if (twitter == null || status == null) return;
retweetOrQuote(twitter, status);
@ -156,11 +146,7 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final Dialog dialog = getDialog();
if (!(dialog instanceof AlertDialog)) return;
final Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
if (positiveButton == null) return;
positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet);
updateTextCount(getDialog(), s, status);
}
@Override
@ -168,17 +154,17 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
}
});
mCommentMenu = view.findViewById(R.id.comment_menu);
final View commentMenu = view.findViewById(R.id.comment_menu);
mPopupMenu = new PopupMenu(context, mCommentMenu, Gravity.NO_GRAVITY,
mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY,
R.attr.actionOverflowMenuStyle, 0);
mCommentMenu.setOnClickListener(new View.OnClickListener() {
commentMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPopupMenu.show();
}
});
mCommentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
mPopupMenu.inflate(R.menu.menu_dialog_comment);
final Menu menu = mPopupMenu.getMenu();
MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status,
@ -194,7 +180,25 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
}
});
return builder.create();
final Dialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
updateTextCount(dialog, mEditComment.getText(), status);
}
});
return dialog;
}
private void updateTextCount(DialogInterface dialog, CharSequence s, ParcelableStatus status) {
if (!(dialog instanceof AlertDialog)) return;
final AlertDialog alertDialog = (AlertDialog) dialog;
final Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (positiveButton == null) return;
positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet);
final String statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id).toString();
final StatusTextCountView textCountView = (StatusTextCountView) alertDialog.findViewById(R.id.comment_text_count);
textCountView.setTextCount(mValidator.getTweetLength(s + " " + statusLink));
}
private ParcelableStatus getStatus() {
@ -204,7 +208,10 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
}
private void retweetOrQuote(AsyncTwitterWrapper twitter, ParcelableStatus status) {
if (mEditComment.length() > 0) {
final Dialog dialog = getDialog();
if (dialog == null) return;
final EditText editComment = ((EditText) dialog.findViewById(R.id.edit_comment));
if (editComment.length() > 0) {
final Menu menu = mPopupMenu.getMenu();
final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status);
final MenuItem linkToQuotedStatus = menu.findItem(R.id.link_to_quoted_status);
@ -217,7 +224,7 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
inReplyToStatusId = status.quoted_id;
statusLink = LinkCreator.getTwitterStatusLink(status.quoted_user_screen_name, status.quoted_id);
}
final String commentText = mEditComment.getText() + " " + statusLink;
final String commentText = editComment.getText() + " " + statusLink;
twitter.updateStatusAsync(new long[]{status.account_id}, commentText, null, null,
linkToQuotedStatus.isChecked() ? inReplyToStatusId : -1, status.is_possibly_sensitive);
} else if (isMyRetweet(status)) {

View File

@ -94,6 +94,7 @@ public class ScheduledStatusesFragment extends AbsContentRecyclerViewFragment<Sc
private List<ScheduledStatus> mData;
public ScheduledStatusesAdapter(Context context) {
super(context);
mContext = context;
mInflater = LayoutInflater.from(context);
setLoadMoreSupported(false);

View File

@ -227,7 +227,7 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.save: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final Bundle args = getArguments();
if (twitter != null && args != null) {
twitter.createSavedSearchAsync(getAccountId(), getQuery());

View File

@ -200,7 +200,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final ParcelableStatus status = mSelectedStatus;
if (status == null) return false;
return Utils.handleMenuItemClick(getActivity(), StatusFragment.this,
getFragmentManager(), getTwitterWrapper(), status, item);
getFragmentManager(), mTwitterWrapper, status, item);
}
};
@ -322,7 +322,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
break;
}
case R.id.favorite_count: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_id, status.id);
@ -412,7 +412,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
return true;
}
case ACTION_STATUS_FAVORITE: {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_id, status.id);
} else {
@ -875,7 +875,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final StatusFragment fragment = adapter.getFragment();
final ParcelableStatus status = adapter.getStatus(layoutPosition);
if (status == null || fragment == null) return false;
final AsyncTwitterWrapper twitter = fragment.getTwitterWrapper();
final AsyncTwitterWrapper twitter = fragment.mTwitterWrapper;
final FragmentActivity activity = fragment.getActivity();
final FragmentManager fm = fragment.getFragmentManager();
if (item.getItemId() == R.id.retweet) {
@ -1158,7 +1158,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@NonNull
@Override
public AsyncTwitterWrapper getTwitterWrapper() {
return mFragment.getTwitterWrapper();
return mFragment.mTwitterWrapper;
}
@Override
@ -1458,7 +1458,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
public long getItemId(int position) {
final ParcelableStatus status = getStatus(position);
if (status != null) return status.id;
return getItemType(position) * 100 + position;
return getItemType(position);
}
@Override

View File

@ -109,7 +109,7 @@ public class TrendsSuggestionsFragment extends AbsContentListViewFragment<Trends
@Override
public void onRefresh() {
if (isRefreshing()) return;
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
twitter.getLocalTrendsAsync(mAccountId, mPreferences.getInt(KEY_LOCAL_TRENDS_WOEID, 1));
}
@ -142,7 +142,7 @@ public class TrendsSuggestionsFragment extends AbsContentListViewFragment<Trends
}
protected void updateRefreshState() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null || !getUserVisibleHint()) return;
setRefreshing(twitter.isLocalTrendsRefreshing());
}

View File

@ -644,7 +644,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
case REQUEST_ADD_TO_LIST: {
if (user == null) return;
if (resultCode == Activity.RESULT_OK && data != null) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableUserList list = data.getParcelableExtra(EXTRA_USER_LIST);
if (list == null || twitter == null) return;
twitter.addUserListMembersAsync(user.account_id, list.id, user);
@ -837,7 +837,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
@Override
public void onPrepareOptionsMenu(final Menu menu) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableUser user = getUser();
final Relationship relationship = mRelationship;
if (twitter == null || user == null) return;
@ -919,7 +919,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableUser user = getUser();
final Relationship relationship = mRelationship;
if (user == null || twitter == null) return false;
@ -1222,7 +1222,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
break;
}
final Relationship relationship = mRelationship;
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (relationship == null || twitter == null) return;
if (relationship.isSourceBlockingTarget()) {
twitter.destroyBlockAsync(user.account_id, user.id);
@ -1469,7 +1469,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
private void updateFollowProgressState() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableUser user = getUser();
if (twitter == null || user == null) {
mFollowButton.setVisibility(View.GONE);
@ -1497,7 +1497,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private void updateRefreshState() {
final ParcelableUser user = getUser();
if (user == null) return;
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final boolean is_creating_friendship = twitter != null
&& twitter.isCreatingFriendship(user.account_id, user.id);
final boolean is_destroying_friendship = twitter != null

View File

@ -213,7 +213,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
super.onActivityCreated(savedInstanceState);
final FragmentActivity activity = getActivity();
final TwidereApplication application = TwidereApplication.getInstance(activity);
mTwitterWrapper = application.getTwitterWrapper();
mProfileImageLoader = application.getMediaLoaderWrapper();
mUserColorNameManager = application.getUserColorNameManager();
mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME,
@ -308,7 +307,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableUserList userList = mUserList;
if (twitter == null || userList == null) return false;
switch (item.getItemId()) {
@ -466,7 +465,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
private long mAccountId;
private long mListId;
private boolean mIsPublic;
private AsyncTwitterWrapper mTwitterWrapper;
@Override
public void onClick(final DialogInterface dialog, final int which) {
@ -491,7 +489,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
mTwitterWrapper = getApplication().getTwitterWrapper();
final Bundle bundle = savedInstanceState == null ? getArguments() : savedInstanceState;
mAccountId = bundle != null ? bundle.getLong(EXTRA_ACCOUNT_ID, -1) : -1;
mListId = bundle != null ? bundle.getLong(EXTRA_LIST_ID, -1) : -1;

View File

@ -26,141 +26,146 @@ import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.provider.TwidereCommands.Refresh;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.PermissionsManager;
import org.mariotaku.twidere.util.dagger.component.DaggerTwidereCommandProviderComponent;
import javax.inject.Inject;
public class TwidereCommandProvider extends ContentProvider implements Constants {
private static final UriMatcher COMMAND_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
private static final UriMatcher COMMAND_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
private static final int CODE_REFRESH_ALL = 10;
private static final int CODE_REFRESH_HOME_TIMELINE = 11;
private static final int CODE_REFRESH_MENTIONS = 12;
private static final int CODE_REFRESH_INBOX = 13;
private static final int CODE_REFRESH_OUTBOX = 14;
private static final int CODE_REFRESH_ALL = 10;
private static final int CODE_REFRESH_HOME_TIMELINE = 11;
private static final int CODE_REFRESH_MENTIONS = 12;
private static final int CODE_REFRESH_INBOX = 13;
private static final int CODE_REFRESH_OUTBOX = 14;
static {
COMMAND_URI_MATCHER.addURI(TwidereCommands.AUTHORITY, Refresh.ACTION_REFRESH_ALL, CODE_REFRESH_ALL);
}
static {
COMMAND_URI_MATCHER.addURI(TwidereCommands.AUTHORITY, Refresh.ACTION_REFRESH_ALL, CODE_REFRESH_ALL);
}
private Context mContext;
private PermissionsManager mPermissionsManager;
private AsyncTwitterWrapper mTwitterWrapper;
private Context mContext;
private PermissionsManager mPermissionsManager;
@Inject
AsyncTwitterWrapper mTwitterWrapper;
@Override
public int delete(final Uri uri, final String where, final String[] whereArgs) {
return 0;
}
@Override
public int delete(@NonNull final Uri uri, final String where, final String[] whereArgs) {
return 0;
}
@Override
public String getType(final Uri uri) {
return null;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
@Override
public Uri insert(final Uri uri, final ContentValues values) {
if (handleInsertCommand(uri, values)) return uri;
return null;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
if (handleInsertCommand(uri, values)) return uri;
return null;
}
@Override
public boolean onCreate() {
mContext = getContext();
final TwidereApplication app = TwidereApplication.getInstance(mContext);
mPermissionsManager = new PermissionsManager(mContext);
mTwitterWrapper = app.getTwitterWrapper();
return true;
}
@Override
public boolean onCreate() {
mContext = getContext();
DaggerTwidereCommandProviderComponent.builder().applicationModule(TwidereApplication.getModule(mContext)).build().inject(this);
mPermissionsManager = new PermissionsManager(mContext);
return true;
}
@Override
public Cursor query(final Uri uri, final String[] projection, final String where, final String[] whereArgs,
final String sortOrder) {
return handleQueryCommand(uri);
}
@Override
public Cursor query(@NonNull final Uri uri, final String[] projection, final String where, final String[] whereArgs,
final String sortOrder) {
return handleQueryCommand(uri);
}
@Override
public int update(final Uri uri, final ContentValues values, final String where, final String[] whereArgs) {
return 0;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String where, final String[] whereArgs) {
return 0;
}
private void checkInsertPermission(final int uri_code) {
switch (uri_code) {
case CODE_REFRESH_ALL:
case CODE_REFRESH_HOME_TIMELINE:
case CODE_REFRESH_MENTIONS:
case CODE_REFRESH_INBOX:
case CODE_REFRESH_OUTBOX: {
if (!mPermissionsManager.checkCallingPermission(PERMISSION_REFRESH))
throw new SecurityException("Executing this command requires level PERMISSION_REFRESH");
}
}
}
private void checkInsertPermission(final int uri_code) {
switch (uri_code) {
case CODE_REFRESH_ALL:
case CODE_REFRESH_HOME_TIMELINE:
case CODE_REFRESH_MENTIONS:
case CODE_REFRESH_INBOX:
case CODE_REFRESH_OUTBOX: {
if (!mPermissionsManager.checkCallingPermission(PERMISSION_REFRESH))
throw new SecurityException("Executing this command requires level PERMISSION_REFRESH");
}
}
}
private void checkQueryPermission(final int uri_code) {
switch (uri_code) {
case CODE_REFRESH_ALL:
case CODE_REFRESH_HOME_TIMELINE:
case CODE_REFRESH_MENTIONS:
case CODE_REFRESH_INBOX:
case CODE_REFRESH_OUTBOX: {
if (!mPermissionsManager.checkCallingPermission(PERMISSION_REFRESH))
throw new SecurityException("Executing this command requires level PERMISSION_REFRESH");
}
}
}
private void checkQueryPermission(final int uri_code) {
switch (uri_code) {
case CODE_REFRESH_ALL:
case CODE_REFRESH_HOME_TIMELINE:
case CODE_REFRESH_MENTIONS:
case CODE_REFRESH_INBOX:
case CODE_REFRESH_OUTBOX: {
if (!mPermissionsManager.checkCallingPermission(PERMISSION_REFRESH))
throw new SecurityException("Executing this command requires level PERMISSION_REFRESH");
}
}
}
private Cursor getEmptyCursor() {
return new MatrixCursor(new String[0]);
}
private Cursor getEmptyCursor() {
return new MatrixCursor(new String[0]);
}
private boolean handleInsertCommand(final Uri uri, final ContentValues values) {
final int uri_code = COMMAND_URI_MATCHER.match(uri);
checkInsertPermission(uri_code);
try {
switch (uri_code) {
case CODE_REFRESH_ALL: {
mTwitterWrapper.refreshAll();
break;
}
default:
return false;
}
// something blah blah blah
} catch (final RuntimeException e) {
e.printStackTrace();
if (Thread.currentThread().getId() != 1)
throw new IllegalStateException("This method cannot be called from non-UI thread");
}
return true;
}
private boolean handleInsertCommand(final Uri uri, final ContentValues values) {
final int uri_code = COMMAND_URI_MATCHER.match(uri);
checkInsertPermission(uri_code);
try {
switch (uri_code) {
case CODE_REFRESH_ALL: {
mTwitterWrapper.refreshAll();
break;
}
default:
return false;
}
// something blah blah blah
} catch (final RuntimeException e) {
e.printStackTrace();
if (Thread.currentThread().getId() != 1)
throw new IllegalStateException("This method cannot be called from non-UI thread");
}
return true;
}
private Cursor handleQueryCommand(final Uri uri) {
final int uri_code = COMMAND_URI_MATCHER.match(uri);
checkQueryPermission(uri_code);
try {
switch (uri_code) {
case CODE_REFRESH_HOME_TIMELINE:
if (mTwitterWrapper.isHomeTimelineRefreshing()) return getEmptyCursor();
case CODE_REFRESH_MENTIONS:
if (mTwitterWrapper.isMentionsTimelineRefreshing()) return getEmptyCursor();
case CODE_REFRESH_INBOX:
if (mTwitterWrapper.isReceivedDirectMessagesRefreshing()) return getEmptyCursor();
case CODE_REFRESH_OUTBOX:
if (mTwitterWrapper.isSentDirectMessagesRefreshing()) return getEmptyCursor();
default:
return null;
}
// something blah blah blah
} catch (final RuntimeException e) {
e.printStackTrace();
if (Thread.currentThread().getId() != 1)
throw new IllegalStateException("This method cannot be called from non-UI thread");
}
return null;
}
private Cursor handleQueryCommand(final Uri uri) {
final int uri_code = COMMAND_URI_MATCHER.match(uri);
checkQueryPermission(uri_code);
try {
switch (uri_code) {
case CODE_REFRESH_HOME_TIMELINE:
if (mTwitterWrapper.isHomeTimelineRefreshing()) return getEmptyCursor();
case CODE_REFRESH_MENTIONS:
if (mTwitterWrapper.isMentionsTimelineRefreshing()) return getEmptyCursor();
case CODE_REFRESH_INBOX:
if (mTwitterWrapper.isReceivedDirectMessagesRefreshing())
return getEmptyCursor();
case CODE_REFRESH_OUTBOX:
if (mTwitterWrapper.isSentDirectMessagesRefreshing()) return getEmptyCursor();
default:
return null;
}
// something blah blah blah
} catch (final RuntimeException e) {
e.printStackTrace();
if (Thread.currentThread().getId() != 1)
throw new IllegalStateException("This method cannot be called from non-UI thread");
}
return null;
}
}

View File

@ -109,6 +109,7 @@ import org.mariotaku.twidere.util.TwidereQueryBuilder.ConversationQueryBuilder;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.collection.CompactHashSet;
import org.mariotaku.twidere.util.dagger.component.DaggerTwidereDataProviderComponent;
import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent;
import java.io.File;
@ -122,6 +123,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import static org.mariotaku.twidere.util.Utils.clearAccountColor;
import static org.mariotaku.twidere.util.Utils.clearAccountName;
import static org.mariotaku.twidere.util.Utils.getAccountIds;
@ -141,7 +144,10 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
@Nullable
private NotificationManager mNotificationManager;
private ReadStateManager mReadStateManager;
@Inject
ReadStateManager mReadStateManager;
@Inject
AsyncTwitterWrapper mTwitterWrapper;
private SharedPreferencesWrapper mPreferences;
private ImagePreloader mImagePreloader;
private Network mNetwork;
@ -165,7 +171,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
};
@Override
public int bulkInsert(final Uri uri, @NonNull final ContentValues[] valuesArray) {
public int bulkInsert(@NonNull final Uri uri, @NonNull final ContentValues[] valuesArray) {
try {
final int tableId = getTableId(uri);
final String table = getTableNameById(tableId);
@ -223,7 +229,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
try {
final int tableId = getTableId(uri);
final String table = getTableNameById(tableId);
@ -263,12 +269,12 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
}
@Override
public String getType(final Uri uri) {
public String getType(@NonNull final Uri uri) {
return null;
}
@Override
public Uri insert(final Uri uri, final ContentValues values) {
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
try {
final int tableId = getTableId(uri);
final String table = getTableNameById(tableId);
@ -412,6 +418,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
@Override
public boolean onCreate() {
final Context context = getContext();
DaggerTwidereDataProviderComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
final TwidereApplication app = TwidereApplication.getInstance(context);
mHandler = new Handler(Looper.getMainLooper());
mDatabaseWrapper = new SQLiteDatabaseWrapper(this);
@ -420,7 +427,6 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
mPreferences.registerOnSharedPreferenceChangeListener(this);
updatePreferences();
mPermissionsManager = new PermissionsManager(context);
mReadStateManager = app.getReadStateManager();
mImagePreloader = new ImagePreloader(context, app.getImageLoader());
final IntentFilter filter = new IntentFilter();
filter.addAction(BROADCAST_HOME_ACTIVITY_ONSTART);
@ -445,8 +451,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
}
@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws FileNotFoundException {
if (uri == null || mode == null) throw new IllegalArgumentException();
public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final String mode) throws FileNotFoundException {
final int table_id = getTableId(uri);
final String table = getTableNameById(table_id);
final int mode_code;
@ -476,7 +481,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
}
@Override
public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs,
public Cursor query(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs,
final String sortOrder) {
try {
final int tableId = getTableId(uri);
@ -566,8 +571,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
return c;
}
case VIRTUAL_TABLE_ID_DRAFTS_UNSENT: {
final TwidereApplication app = TwidereApplication.getInstance(getContext());
final AsyncTwitterWrapper twitter = app.getTwitterWrapper();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final RawItemArray sendingIds = new RawItemArray(twitter.getSendingDraftIds());
final Expression where;
if (selection != null) {
@ -592,7 +596,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
}
@Override
public int update(final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) {
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) {
try {
final int tableId = getTableId(uri);
final String table = getTableNameById(tableId);

View File

@ -48,8 +48,7 @@ public class NotificationReceiver extends BroadcastReceiver implements Constants
final String tag = getPositionTag(uri.getLastPathSegment());
if (tag == null) return;
final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
final TwidereApplication app = TwidereApplication.getInstance(context);
final ReadStateManager manager = app.getReadStateManager();
final ReadStateManager manager = TwidereApplication.getModule(context).getReadStateManager();
final String paramReadPosition, paramReadPositions;
if (!TextUtils.isEmpty(paramReadPosition = uri.getQueryParameter(QUERY_PARAM_READ_POSITION))) {
manager.setPosition(Utils.getReadPositionTagWithAccounts(tag, accountId),

View File

@ -85,6 +85,7 @@ import org.mariotaku.twidere.util.StatusShortenerInterface;
import org.mariotaku.twidere.util.TwidereValidator;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.component.DaggerBackgroundOperationServiceComponent;
import org.mariotaku.twidere.util.io.ContentLengthInputStream;
import org.mariotaku.twidere.util.io.ContentLengthInputStream.ReadListener;
@ -96,6 +97,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import edu.tsinghua.hotmobi.HotMobiLogger;
import edu.tsinghua.hotmobi.model.TimelineType;
import edu.tsinghua.hotmobi.model.TweetEvent;
@ -114,7 +117,8 @@ public class BackgroundOperationService extends IntentService implements Constan
private SharedPreferences mPreferences;
private ContentResolver mResolver;
private NotificationManager mNotificationManager;
private AsyncTwitterWrapper mTwitter;
@Inject
AsyncTwitterWrapper mTwitter;
private MediaUploaderInterface mUploader;
private StatusShortenerInterface mShortener;
@ -128,13 +132,13 @@ public class BackgroundOperationService extends IntentService implements Constan
@Override
public void onCreate() {
super.onCreate();
DaggerBackgroundOperationServiceComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
final TwidereApplication app = TwidereApplication.getInstance(this);
mHandler = new Handler();
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
mValidator = new TwidereValidator(this);
mResolver = getContentResolver();
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mTwitter = app.getTwitterWrapper();
final String uploaderComponent = mPreferences.getString(KEY_MEDIA_UPLOADER, null);
final String shortenerComponent = mPreferences.getString(KEY_STATUS_SHORTENER, null);
mUseUploader = !ServicePickerPreference.isNoneValue(uploaderComponent);
@ -222,6 +226,7 @@ public class BackgroundOperationService extends IntentService implements Constan
final Expression where = Expression.equals(Drafts._ID, draftId);
final ContentResolver cr = getContentResolver();
final Cursor c = cr.query(Drafts.CONTENT_URI, Drafts.COLUMNS, where.getSQL(), null, null);
if (c == null) return;
final DraftItem.CursorIndices i = new DraftItem.CursorIndices(c);
final DraftItem item;
try {
@ -319,7 +324,7 @@ public class BackgroundOperationService extends IntentService implements Constan
final ContentValues draftValues = ContentValuesCreator.createStatusDraft(item,
ParcelableAccount.getAccountIds(item.accounts));
final Uri draftUri = mResolver.insert(Drafts.CONTENT_URI, draftValues);
final long draftId = ParseUtils.parseLong(draftUri.getLastPathSegment(), -1);
final long draftId = draftUri != null ? ParseUtils.parseLong(draftUri.getLastPathSegment(), -1) : -1;
mTwitter.addSendingDraftId(draftId);
final List<SingleResponse<ParcelableStatus>> result = updateStatus(builder, item);
boolean failed = false;

View File

@ -39,9 +39,12 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.receiver.PowerStateReceiver;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.dagger.component.DaggerRefreshServiceComponent;
import java.util.Arrays;
import javax.inject.Inject;
import edu.tsinghua.hotmobi.HotMobiLogger;
import static org.mariotaku.twidere.util.ParseUtils.parseInt;
@ -59,7 +62,8 @@ public class RefreshService extends Service implements Constants {
private SharedPreferencesWrapper mPreferences;
private AlarmManager mAlarmManager;
private AsyncTwitterWrapper mTwitterWrapper;
@Inject
AsyncTwitterWrapper mTwitterWrapper;
private PendingIntent mPendingRefreshHomeTimelineIntent, mPendingRefreshMentionsIntent,
mPendingRefreshDirectMessagesIntent, mPendingRefreshTrendsIntent;
@ -148,9 +152,9 @@ public class RefreshService extends Service implements Constants {
@Override
public void onCreate() {
super.onCreate();
DaggerRefreshServiceComponent.builder().applicationModule(TwidereApplication.getModule(this)).build().inject(this);
mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final TwidereApplication app = TwidereApplication.getInstance(this);
mTwitterWrapper = app.getTwitterWrapper();
mPreferences = SharedPreferencesWrapper.getInstance(app, SHARED_PREFERENCES_NAME, MODE_PRIVATE);
mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0, new Intent(
BROADCAST_REFRESH_HOME_TIMELINE), 0);

View File

@ -0,0 +1,51 @@
/*
* 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.util;
import android.app.Activity;
import java.util.HashSet;
/**
* Created by mariotaku on 15/10/5.
*/
public class ActivityStack {
private final HashSet<Integer> mInternalStack = new HashSet<>();
public void dispatchStart(Activity activity) {
mInternalStack.add(System.identityHashCode(activity));
}
public void dispatchStop(Activity activity) {
mInternalStack.remove(System.identityHashCode(activity));
}
public int size() {
return mInternalStack.size();
}
public boolean isEmpty() {
return mInternalStack.isEmpty();
}
}

View File

@ -286,11 +286,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
return true;
}
public static AsyncTwitterWrapper getInstance(final Context context) {
final TwidereApplication application = TwidereApplication.getInstance(context);
return application.getTwitterWrapper();
}
public int getLocalTrendsAsync(final long accountId, final int woeid) {
mAsyncTaskManager.cancel(mGetLocalTrendsTaskId);
final GetLocalTrendsTask task = new GetLocalTrendsTask(accountId, woeid);

View File

@ -40,6 +40,7 @@ import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
import java.util.ArrayList;
import java.util.Arrays;
@ -49,6 +50,8 @@ import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.inject.Inject;
import static org.mariotaku.twidere.util.Utils.getAccountScreenNames;
import static org.mariotaku.twidere.util.content.ContentResolverUtils.bulkDelete;
import static org.mariotaku.twidere.util.content.ContentResolverUtils.bulkInsert;
@ -58,7 +61,8 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback,
private TwidereApplication mApplication;
private AsyncTwitterWrapper mTwitterWrapper;
@Inject
AsyncTwitterWrapper mTwitterWrapper;
private MultiSelectManager mMultiSelectManager;
@ -71,6 +75,7 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback,
public static final int MENU_GROUP = 201;
public MultiSelectEventHandler(final BaseAppCompatActivity activity) {
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(activity)).build().inject(this);
mActivity = activity;
}
@ -79,7 +84,6 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback,
*/
public void dispatchOnCreate() {
mApplication = mActivity.getTwidereApplication();
mTwitterWrapper = mApplication.getTwitterWrapper();
mMultiSelectManager = mApplication.getMultiSelectManager();
}

View File

@ -3362,9 +3362,6 @@ public final class Utils implements Constants {
private static boolean isMyStatus(ParcelableStatus status) {
if (isMyRetweet(status)) return true;
if (status.is_quote) {
return status.account_id == status.quoted_user_id;
}
return status.account_id == status.user_id;
}

View File

@ -0,0 +1,72 @@
/*
* 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.util.dagger;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.ActivityStack;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ReadStateManager;
import dagger.Module;
import dagger.Provides;
/**
* Created by mariotaku on 15/10/5.
*/
@Module
public class ApplicationModule {
private final ActivityStack activityStack;
private final AsyncTwitterWrapper asyncTwitterWrapper;
private final ReadStateManager readStateManager;
public ApplicationModule(TwidereApplication application) {
activityStack = new ActivityStack();
asyncTwitterWrapper = new AsyncTwitterWrapper(application);
readStateManager = new ReadStateManager(application);
}
@Provides
ActivityStack provideActivityStack() {
return activityStack;
}
@Provides
AsyncTwitterWrapper provideAsyncTwitterWrapper() {
return asyncTwitterWrapper;
}
@Provides
ReadStateManager provideReadStateManager() {
return readStateManager;
}
public ActivityStack getActivityStack() {
return activityStack;
}
public AsyncTwitterWrapper getAsyncTwitterWrapper() {
return asyncTwitterWrapper;
}
public ReadStateManager getReadStateManager() {
return readStateManager;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.service.BackgroundOperationService;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface BackgroundOperationServiceComponent {
void inject(BackgroundOperationService object);
}

View File

@ -0,0 +1,35 @@
/*
* 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.util.dagger.component;
import android.support.v7.widget.RecyclerView;
import org.mariotaku.twidere.adapter.BaseAdapter;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface BaseAdapterComponent {
void inject(BaseAdapter<RecyclerView.ViewHolder> object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface BaseAppCompatActivityComponent {
void inject(BaseAppCompatActivity object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.fragment.BaseListFragment;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface BaseListFragmentComponent {
void inject(BaseListFragment object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface BaseSupportDialogFragmentComponent {
void inject(BaseSupportDialogFragment object);
}

View File

@ -0,0 +1,42 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.fragment.BaseFragment;
import org.mariotaku.twidere.fragment.support.BaseSupportFragment;
import org.mariotaku.twidere.util.MultiSelectEventHandler;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import org.mariotaku.twidere.view.holder.StatusViewHolder;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface GeneralComponent {
void inject(StatusViewHolder.DummyStatusHolderAdapter object);
void inject(BaseFragment object);
void inject(BaseSupportFragment object);
void inject(MultiSelectEventHandler object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.service.RefreshService;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface RefreshServiceComponent {
void inject(RefreshService object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.activity.support.ThemedFragmentActivity;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface ThemedFragmentActivityComponent {
void inject(ThemedFragmentActivity object);
}

View File

@ -0,0 +1,34 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.provider.TwidereCommandProvider;
import org.mariotaku.twidere.provider.TwidereDataProvider;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface TwidereCommandProviderComponent {
void inject(TwidereCommandProvider object);
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.dagger.component;
import org.mariotaku.twidere.provider.TwidereDataProvider;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
import dagger.Component;
/**
* Created by mariotaku on 15/10/5.
*/
@Component(modules = ApplicationModule.class)
public interface TwidereDataProviderComponent {
void inject(TwidereDataProvider object);
}

View File

@ -31,6 +31,7 @@ import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.util.TwitterCardUtils;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.component.DaggerGeneralComponent;
import org.mariotaku.twidere.view.CardMediaContainer;
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
import org.mariotaku.twidere.view.ForegroundColorView;
@ -40,6 +41,8 @@ import org.mariotaku.twidere.view.iface.IColorLabelView;
import java.util.Locale;
import javax.inject.Inject;
import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText;
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
@ -451,7 +454,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
private final SharedPreferencesWrapper preferences;
private final MediaLoaderWrapper loader;
private final MediaLoadingHandler handler;
private final AsyncTwitterWrapper twitter;
@Inject
AsyncTwitterWrapper twitter;
private final TwidereLinkify linkify;
private final UserColorNameManager manager;
@ -467,12 +471,12 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
private boolean shouldShowAccountsColor;
public DummyStatusHolderAdapter(Context context) {
DaggerGeneralComponent.builder().applicationModule(TwidereApplication.getModule(context)).build().inject(this);
this.context = context;
preferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final TwidereApplication app = TwidereApplication.getInstance(context);
loader = app.getMediaLoaderWrapper();
handler = new MediaLoadingHandler(R.id.media_preview_progress);
twitter = app.getTwitterWrapper();
manager = app.getUserColorNameManager();
linkify = new TwidereLinkify(null);
updateOptions();

View File

@ -18,7 +18,7 @@
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/status_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -32,42 +32,53 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
<RelativeLayout
android:id="@+id/comment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_height="wrap_content">
<org.mariotaku.twidere.view.ComposeMaterialEditText
android:id="@+id/edit_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:completionThreshold="1"
android:focusable="true"
android:hint="@string/comment_hint"
android:inputType="textShortMessage|textMultiLine"
android:singleLine="false"
android:visibility="visible"
app:met_baseColor="?android:textColorSecondary"
app:met_helperTextColor="?android:textColorSecondary"
app:met_maxCharacters="140"
app:met_textColor="?android:textColorPrimary"
app:met_textColorHint="?android:textColorTertiary">
android:visibility="visible">
<requestFocus />
</org.mariotaku.twidere.view.ComposeMaterialEditText>
<org.mariotaku.twidere.view.StatusTextCountView
android:id="@+id/comment_text_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/comment_menu"
android:layout_alignLeft="@+id/edit_comment"
android:layout_alignStart="@+id/edit_comment"
android:layout_alignTop="@+id/comment_menu"
android:layout_below="@+id/edit_comment"
android:layout_toLeftOf="@+id/comment_menu"
android:layout_toStartOf="@+id/comment_menu"
android:gravity="center_vertical|start"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_normal"
tools:text="140" />
<org.mariotaku.twidere.view.ActionIconButton
android:id="@+id/comment_menu"
style="?cardActionButtonStyle"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_weight="0"
android:layout_alignEnd="@+id/edit_comment"
android:layout_alignRight="@+id/edit_comment"
android:layout_below="@+id/edit_comment"
android:color="?android:textColorTertiary"
android:focusable="false"
android:src="@drawable/ic_action_more_vertical" />
</LinearLayout>
</RelativeLayout>
<include layout="@layout/card_item_status_common" />
</LinearLayout>