fixed crashes caused by wrong profile image view cast

This commit is contained in:
Mariotaku Lee 2015-06-22 20:56:44 +08:00
parent 630c6709e2
commit 6324796383
5 changed files with 18 additions and 16 deletions

View File

@ -31,6 +31,7 @@ import static org.mariotaku.twidere.util.Utils.copyStream;
public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implements Constants {
public static final long UPLOAD_INTERVAL_MILLIS = 1000 * 60 * 60 * 24;
public static final String LAST_UPLOAD_TIME = "last_upload_time";
private static final String PROFILE_SERVER_URL = "http://spice.hot-mobile.org/spice/usage";
@ -87,8 +88,8 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implem
final SharedPreferences prefs = context.getSharedPreferences("spice_data_profiling", Context.MODE_PRIVATE);
if (prefs.contains(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD)) {
final long lastUpload = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, System.currentTimeMillis());
if (prefs.contains(LAST_UPLOAD_TIME)) {
final long lastUpload = prefs.getLong(LAST_UPLOAD_TIME, System.currentTimeMillis());
final double deltaDays = (System.currentTimeMillis() - lastUpload) / UPLOAD_INTERVAL_MILLIS;
if (deltaDays < 1) {
SpiceProfilingUtil.log("Last uploaded was conducted in 1 day ago.");
@ -99,7 +100,7 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implem
final File root = context.getFilesDir();
final File[] spiceFiles = root.listFiles(new SpiceFileFilter());
uploadToServer(spiceFiles);
prefs.edit().putLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, System.currentTimeMillis()).apply();
prefs.edit().putLong(LAST_UPLOAD_TIME, System.currentTimeMillis()).apply();
return null;
}
@ -144,4 +145,9 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implem
}
}
}
public static long getLastUploadTime(final Context context) {
final SharedPreferences prefs = context.getSharedPreferences("spice_data_profiling", Context.MODE_PRIVATE);
return prefs.getLong(LAST_UPLOAD_TIME, -1);
}
}

View File

@ -177,8 +177,6 @@ public interface Constants extends TwidereConstants {
// SharedPreferences constants
@Preference(type = BOOLEAN, exportable = false)
String KEY_USAGE_STATISTICS = "usage_statistics";
@Preference(type = BOOLEAN, exportable = false)
String KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD = "usage_statistics_last_successful_upload";
@Preference(type = STRING, exportable = false)
String KEY_DEVICE_SERIAL = "device_serial";
}

View File

@ -48,7 +48,7 @@ import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.ShapedImageView;
import org.mariotaku.twidere.view.ProfileImageView;
public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implements Constants {
@ -70,7 +70,6 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
private final EditText mEditText;
private final boolean mDisplayProfileImage;
private final int mProfileImageStyle;
private int mProfileImageUrlIdx, mNameIdx, mScreenNameIdx, mUserIdIdx;
private char mToken = '@';
@ -90,7 +89,6 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
mProfileImageLoader = app.getMediaLoaderWrapper();
mDatabase = app.getSQLiteDatabase();
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
mProfileImageStyle = Utils.getProfileImageStyle(mPreferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
}
public UserHashtagAutoCompleteAdapter(final EditText view) {
@ -102,7 +100,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
if (isCursorClosed()) return;
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
final ShapedImageView icon = (ShapedImageView) view.findViewById(android.R.id.icon);
final ProfileImageView icon = (ProfileImageView) view.findViewById(android.R.id.icon);
// Clear images in order to prevent images in recycled view shown.
icon.setImageDrawable(null);
@ -119,13 +117,11 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
if (mDisplayProfileImage) {
final String profileImageUrl = cursor.getString(mProfileImageUrlIdx);
mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
icon.setStyle(mProfileImageStyle);
} else {
mProfileImageLoader.cancelDisplayTask(icon);
}
icon.clearColorFilter();
} else {
icon.setStyle(mProfileImageStyle);
icon.setImageResource(R.drawable.ic_action_hashtag);
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
}

View File

@ -62,10 +62,12 @@ public class ConnectivityStateReceiver extends BroadcastReceiver implements Cons
}
final boolean isWifi = Utils.isOnWifi(context.getApplicationContext());
final boolean isCharging = SpiceProfilingUtil.isCharging(context.getApplicationContext());
final long currentTime = System.currentTimeMillis();
final long lastSuccessfulTime = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, -1);
if (isWifi && isCharging && (currentTime - lastSuccessfulTime) > SpiceAsyUploadTask.UPLOAD_INTERVAL_MILLIS) {
AsyncTaskUtils.executeTask(new SpiceAsyUploadTask(context));
if (isWifi && isCharging) {
final long currentTime = System.currentTimeMillis();
final long lastSuccessfulTime = SpiceAsyUploadTask.getLastUploadTime(context);
if ((currentTime - lastSuccessfulTime) > SpiceAsyUploadTask.UPLOAD_INTERVAL_MILLIS) {
AsyncTaskUtils.executeTask(new SpiceAsyUploadTask(context));
}
}
}
}

View File

@ -26,7 +26,7 @@
android:orientation="horizontal"
android:padding="@dimen/element_spacing_msmall">
<org.mariotaku.twidere.view.ProfileImageView
<org.mariotaku.twidere.view.ShapedImageView
android:id="@android:id/icon"
style="?profileImageStyleLarge"
android:layout_width="wrap_content"