fixed crashes caused by wrong profile image view cast
This commit is contained in:
parent
630c6709e2
commit
6324796383
|
@ -31,6 +31,7 @@ import static org.mariotaku.twidere.util.Utils.copyStream;
|
||||||
public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implements Constants {
|
public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implements Constants {
|
||||||
|
|
||||||
public static final long UPLOAD_INTERVAL_MILLIS = 1000 * 60 * 60 * 24;
|
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";
|
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);
|
final SharedPreferences prefs = context.getSharedPreferences("spice_data_profiling", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
if (prefs.contains(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD)) {
|
if (prefs.contains(LAST_UPLOAD_TIME)) {
|
||||||
final long lastUpload = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, System.currentTimeMillis());
|
final long lastUpload = prefs.getLong(LAST_UPLOAD_TIME, System.currentTimeMillis());
|
||||||
final double deltaDays = (System.currentTimeMillis() - lastUpload) / UPLOAD_INTERVAL_MILLIS;
|
final double deltaDays = (System.currentTimeMillis() - lastUpload) / UPLOAD_INTERVAL_MILLIS;
|
||||||
if (deltaDays < 1) {
|
if (deltaDays < 1) {
|
||||||
SpiceProfilingUtil.log("Last uploaded was conducted in 1 day ago.");
|
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 root = context.getFilesDir();
|
||||||
final File[] spiceFiles = root.listFiles(new SpiceFileFilter());
|
final File[] spiceFiles = root.listFiles(new SpiceFileFilter());
|
||||||
uploadToServer(spiceFiles);
|
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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,8 +177,6 @@ public interface Constants extends TwidereConstants {
|
||||||
// SharedPreferences constants
|
// SharedPreferences constants
|
||||||
@Preference(type = BOOLEAN, exportable = false)
|
@Preference(type = BOOLEAN, exportable = false)
|
||||||
String KEY_USAGE_STATISTICS = "usage_statistics";
|
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)
|
@Preference(type = STRING, exportable = false)
|
||||||
String KEY_DEVICE_SERIAL = "device_serial";
|
String KEY_DEVICE_SERIAL = "device_serial";
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.mariotaku.twidere.util.ParseUtils;
|
||||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||||
import org.mariotaku.twidere.util.Utils;
|
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 {
|
public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implements Constants {
|
||||||
|
@ -70,7 +70,6 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||||
private final EditText mEditText;
|
private final EditText mEditText;
|
||||||
|
|
||||||
private final boolean mDisplayProfileImage;
|
private final boolean mDisplayProfileImage;
|
||||||
private final int mProfileImageStyle;
|
|
||||||
|
|
||||||
private int mProfileImageUrlIdx, mNameIdx, mScreenNameIdx, mUserIdIdx;
|
private int mProfileImageUrlIdx, mNameIdx, mScreenNameIdx, mUserIdIdx;
|
||||||
private char mToken = '@';
|
private char mToken = '@';
|
||||||
|
@ -90,7 +89,6 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||||
mProfileImageLoader = app.getMediaLoaderWrapper();
|
mProfileImageLoader = app.getMediaLoaderWrapper();
|
||||||
mDatabase = app.getSQLiteDatabase();
|
mDatabase = app.getSQLiteDatabase();
|
||||||
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||||
mProfileImageStyle = Utils.getProfileImageStyle(mPreferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserHashtagAutoCompleteAdapter(final EditText view) {
|
public UserHashtagAutoCompleteAdapter(final EditText view) {
|
||||||
|
@ -102,7 +100,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||||
if (isCursorClosed()) return;
|
if (isCursorClosed()) return;
|
||||||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||||
final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
|
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.
|
// Clear images in order to prevent images in recycled view shown.
|
||||||
icon.setImageDrawable(null);
|
icon.setImageDrawable(null);
|
||||||
|
@ -119,13 +117,11 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||||
if (mDisplayProfileImage) {
|
if (mDisplayProfileImage) {
|
||||||
final String profileImageUrl = cursor.getString(mProfileImageUrlIdx);
|
final String profileImageUrl = cursor.getString(mProfileImageUrlIdx);
|
||||||
mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
|
mProfileImageLoader.displayProfileImage(icon, profileImageUrl);
|
||||||
icon.setStyle(mProfileImageStyle);
|
|
||||||
} else {
|
} else {
|
||||||
mProfileImageLoader.cancelDisplayTask(icon);
|
mProfileImageLoader.cancelDisplayTask(icon);
|
||||||
}
|
}
|
||||||
icon.clearColorFilter();
|
icon.clearColorFilter();
|
||||||
} else {
|
} else {
|
||||||
icon.setStyle(mProfileImageStyle);
|
|
||||||
icon.setImageResource(R.drawable.ic_action_hashtag);
|
icon.setImageResource(R.drawable.ic_action_hashtag);
|
||||||
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
|
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,12 @@ public class ConnectivityStateReceiver extends BroadcastReceiver implements Cons
|
||||||
}
|
}
|
||||||
final boolean isWifi = Utils.isOnWifi(context.getApplicationContext());
|
final boolean isWifi = Utils.isOnWifi(context.getApplicationContext());
|
||||||
final boolean isCharging = SpiceProfilingUtil.isCharging(context.getApplicationContext());
|
final boolean isCharging = SpiceProfilingUtil.isCharging(context.getApplicationContext());
|
||||||
final long currentTime = System.currentTimeMillis();
|
if (isWifi && isCharging) {
|
||||||
final long lastSuccessfulTime = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, -1);
|
final long currentTime = System.currentTimeMillis();
|
||||||
if (isWifi && isCharging && (currentTime - lastSuccessfulTime) > SpiceAsyUploadTask.UPLOAD_INTERVAL_MILLIS) {
|
final long lastSuccessfulTime = SpiceAsyUploadTask.getLastUploadTime(context);
|
||||||
AsyncTaskUtils.executeTask(new SpiceAsyUploadTask(context));
|
if ((currentTime - lastSuccessfulTime) > SpiceAsyUploadTask.UPLOAD_INTERVAL_MILLIS) {
|
||||||
|
AsyncTaskUtils.executeTask(new SpiceAsyUploadTask(context));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="@dimen/element_spacing_msmall">
|
android:padding="@dimen/element_spacing_msmall">
|
||||||
|
|
||||||
<org.mariotaku.twidere.view.ProfileImageView
|
<org.mariotaku.twidere.view.ShapedImageView
|
||||||
android:id="@android:id/icon"
|
android:id="@android:id/icon"
|
||||||
style="?profileImageStyleLarge"
|
style="?profileImageStyleLarge"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue