Fixed feed refresh issues, FTUX UI issues.

This commit is contained in:
RyanBateman 2012-10-01 11:17:44 -04:00
parent 74e2a93fda
commit c9df424b57
12 changed files with 121 additions and 33 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.newsblur"
android:versionCode="9"
android:versionName="0.9.30" >
android:versionCode="10"
android:versionName="0.9.35" >
<uses-sdk
android:minSdkVersion="8"

View file

@ -2,7 +2,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/item_background" >
android:background="@drawable/login_background" >
<FrameLayout
android:id="@+id/login_progress_container"

View file

@ -24,14 +24,24 @@
android:textColor="@color/white"
android:textSize="16dp" />
<ProgressBar
android:id="@+id/login_logging_in_progress"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_toLeftOf="@id/login_logging_in"
android:indeterminateOnly="true"
android:visibility="visible" />
<ImageView
android:id="@+id/login_profile_picture"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_toLeftOf="@id/login_logging_in"
android:src="@drawable/world" />
android:visibility="gone"
android:layout_toLeftOf="@id/login_logging_in" />
</RelativeLayout>
<RelativeLayout

View file

@ -80,7 +80,6 @@ public abstract class ItemsList extends SherlockFragmentActivity implements Sync
@Override
public void updateAfterSync() {
Log.d(TAG , "Redrawing UI");
if (itemListFragment != null) {
itemListFragment.hasUpdated();
} else {

View file

@ -246,7 +246,6 @@ public class FeedProvider extends ContentProvider {
return db.rawQuery("SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
" ON " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID + " = " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FEED_ID +
" WHERE (" + DatabaseConstants.FEED_NEGATIVE_COUNT + " + " + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 " +
" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE", selectionArgs);
// Query for a specific feed

View file

@ -407,6 +407,7 @@ public class MixedExpandableListAdapter extends BaseExpandableListAdapter{
private synchronized void releaseCursorHelpers() {
for (int pos = mChildrenCursorHelpers.size() - 1; pos >= 0; pos--) {
mChildrenCursorHelpers.valueAt(pos).deactivate();
}
mChildrenCursorHelpers.clear();
@ -521,6 +522,7 @@ public class MixedExpandableListAdapter extends BaseExpandableListAdapter{
mCursor.unregisterContentObserver(mContentObserver);
mCursor.unregisterDataSetObserver(mDataSetObserver);
mCursor.close();
mCursor.deactivate();
mCursor = null;
}

View file

@ -2,6 +2,8 @@ package com.newsblur.domain;
import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.annotations.SerializedName;
import com.newsblur.database.DatabaseConstants;
@ -90,8 +92,17 @@ public class Feed {
feed.positiveCount = childCursor.getInt(childCursor.getColumnIndex(DatabaseConstants.FEED_POSITIVE_COUNT));
feed.subscribers = childCursor.getString(childCursor.getColumnIndex(DatabaseConstants.FEED_SUBSCRIBERS));
feed.title = childCursor.getString(childCursor.getColumnIndex(DatabaseConstants.FEED_TITLE));
childCursor.close();
return feed;
}
@Override
public boolean equals(Object o) {
Feed otherFeed = (Feed) o;
boolean isEquals = (TextUtils.equals(feedId, otherFeed.feedId) &&
negativeCount == otherFeed.negativeCount &&
neutralCount == otherFeed.neutralCount &&
positiveCount == otherFeed.positiveCount);
return isEquals;
}
}

View file

@ -2,6 +2,7 @@ package com.newsblur.domain;
import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import com.newsblur.database.DatabaseConstants;
@ -32,5 +33,9 @@ public class Folder {
return folder;
}
@Override
public boolean equals(Object otherFolder) {
return TextUtils.equals(((Folder) otherFolder).getId(), getId());
}
}

View file

@ -2,6 +2,7 @@ package com.newsblur.domain;
import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import com.newsblur.database.DatabaseConstants;
@ -41,7 +42,9 @@ public class SocialFeed {
}
public static SocialFeed fromCursor(final Cursor cursor) {
cursor.moveToFirst();
if (cursor.isBeforeFirst()) {
cursor.moveToFirst();
}
SocialFeed socialFeed = new SocialFeed();
socialFeed.userId = cursor.getString(cursor.getColumnIndex(DatabaseConstants.SOCIAL_FEED_ID));
socialFeed.username = cursor.getString(cursor.getColumnIndex(DatabaseConstants.SOCIAL_FEED_USERNAME));
@ -53,4 +56,15 @@ public class SocialFeed {
return socialFeed;
}
@Override
public boolean equals(Object o) {
SocialFeed otherFeed = (SocialFeed) o;
boolean equals = (TextUtils.equals(userId, otherFeed.userId) &&
positiveCount == otherFeed.positiveCount &&
neutralCount == otherFeed.neutralCount &&
negativeCount == otherFeed.negativeCount &&
TextUtils.equals(photoUrl, otherFeed.photoUrl));
return equals;
}
}

View file

@ -25,6 +25,7 @@ import com.newsblur.service.DetachableResultReceiver;
import com.newsblur.service.DetachableResultReceiver.Receiver;
import com.newsblur.service.SyncService;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.UIUtils;
public class LoginProgressFragment extends Fragment implements Receiver {
@ -34,7 +35,7 @@ public class LoginProgressFragment extends Fragment implements Receiver {
private TextView updateStatus, retrievingFeeds, letsGo;
private ImageView loginProfilePicture;
private int CURRENT_STATUS = -1;
private ProgressBar feedProgress;
private ProgressBar feedProgress, loggingInProgress;
private LoginTask loginTask;
private String username;
private String password;
@ -72,6 +73,7 @@ public class LoginProgressFragment extends Fragment implements Receiver {
retrievingFeeds = (TextView) v.findViewById(R.id.login_retrieving_feeds);
letsGo = (TextView) v.findViewById(R.id.login_lets_go);
feedProgress = (ProgressBar) v.findViewById(R.id.login_feed_progress);
loggingInProgress = (ProgressBar) v.findViewById(R.id.login_logging_in_progress);
loginProfilePicture = (ImageView) v.findViewById(R.id.login_profile_picture);
// password.setOnEditorActionListener(this);
@ -113,9 +115,11 @@ public class LoginProgressFragment extends Fragment implements Receiver {
if (result.authenticated) {
final Animation a = AnimationUtils.loadAnimation(getActivity(), R.anim.text_down);
updateStatus.setText(R.string.login_logged_in);
loggingInProgress.setVisibility(View.GONE);
updateStatus.startAnimation(a);
loginProfilePicture.setImageBitmap(PrefsUtils.getUserImage(getActivity()));
loginProfilePicture.setVisibility(View.VISIBLE);
loginProfilePicture.setImageBitmap(UIUtils.roundBitmap(PrefsUtils.getUserImage(getActivity())));
feedProgress.setVisibility(View.VISIBLE);
Log.d(TAG, "Authenticated. Starting receiver.");

View file

@ -24,8 +24,6 @@ import com.newsblur.service.DetachableResultReceiver;
public class LoginRegisterFragment extends Fragment implements OnClickListener {
private static final String TAG = "LoginFragment";
public APIManager apiManager;
private EditText username, password;
private ViewSwitcher viewSwitcher;

View file

@ -3,6 +3,8 @@ package com.newsblur.network;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
@ -11,6 +13,7 @@ import org.apache.http.HttpStatus;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@ -26,6 +29,7 @@ import com.newsblur.domain.Classifier;
import com.newsblur.domain.Comment;
import com.newsblur.domain.Feed;
import com.newsblur.domain.FeedResult;
import com.newsblur.domain.Folder;
import com.newsblur.domain.Reply;
import com.newsblur.domain.SocialFeed;
import com.newsblur.domain.Story;
@ -203,7 +207,7 @@ public class APIManager {
contentResolver.insert(storyUri, story.getValues());
insertComments(story);
}
for (UserProfile user : storiesResponse.users) {
contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
}
@ -237,11 +241,11 @@ public class APIManager {
contentResolver.insert(storyUri, story.getValues());
insertComments(story);
}
for (UserProfile user : storiesResponse.users) {
contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
}
return storiesResponse;
} else {
return null;
@ -257,9 +261,9 @@ public class APIManager {
if (!TextUtils.isEmpty(pageNumber)) {
values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
}
final APIResponse response = client.get(APIConstants.URL_SHARED_RIVER_STORIES, values);
SocialFeedResponse storiesResponse = gson.fromJson(response.responseString, SocialFeedResponse.class);
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
@ -281,7 +285,7 @@ public class APIManager {
insertComments(story);
}
for (UserProfile user : storiesResponse.userProfiles) {
contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
}
@ -323,7 +327,7 @@ public class APIManager {
contentResolver.insert(storyUri, story.getValues());
contentResolver.insert(storySocialUri, story.getValues());
}
if (socialFeedResponse.userProfiles != null) {
for (UserProfile user : socialFeedResponse.userProfiles) {
contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
@ -422,37 +426,79 @@ public class APIManager {
public void getFolderFeedMapping(boolean doUpdateCounts) {
final APIClient client = new APIClient(context);
long currentTime = System.currentTimeMillis();
final APIResponse response = client.get(doUpdateCounts ? APIConstants.URL_FEEDS : APIConstants.URL_FEEDS_NO_UPDATE);
final FeedFolderResponse feedUpdate = gson.fromJson(response.responseString, FeedFolderResponse.class);
Log.d(TAG, "Took " + (System.currentTimeMillis() - currentTime) + "ms to retrieve feeds");
currentTime = System.currentTimeMillis();
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
for (final Entry<String, Feed> entry : feedUpdate.feeds.entrySet()) {
final Feed feed = entry.getValue();
contentResolver.insert(FeedProvider.FEEDS_URI, feed.getValues());
HashMap<String, Feed> existingFeeds = getExistingFeeds();
int insertionCount = 0;
for (String newFeedId : feedUpdate.feeds.keySet()) {
if (existingFeeds.get(newFeedId) == null || !feedUpdate.feeds.get(newFeedId).equals(existingFeeds.get(newFeedId))) {
insertionCount += 1;
contentResolver.insert(FeedProvider.FEEDS_URI, feedUpdate.feeds.get(newFeedId).getValues());
}
}
for (String olderFeedId : existingFeeds.keySet()) {
if (feedUpdate.feeds.get(olderFeedId) == null) {
Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(olderFeedId).build();
contentResolver.delete(feedUri, null, null);
}
}
for (final SocialFeed feed : feedUpdate.socialFeeds) {
contentResolver.insert(FeedProvider.SOCIAL_FEEDS_URI, feed.getValues());
}
String unsortedFolderName = context.getResources().getString(R.string.unsorted_folder_name);
Cursor folderCursor = contentResolver.query(FeedProvider.FOLDERS_URI, null, null, null, null);
folderCursor.moveToFirst();
HashSet<String> existingFolders = new HashSet<String>();
while (!folderCursor.isAfterLast()) {
existingFolders.add(Folder.fromCursor(folderCursor).getName());
folderCursor.moveToNext();
}
folderCursor.close();
for (final Entry<String, List<Long>> entry : feedUpdate.folders.entrySet()) {
String folderName = TextUtils.isEmpty(entry.getKey()) ? unsortedFolderName : entry.getKey();
final ContentValues folderValues = new ContentValues();
folderValues.put(DatabaseConstants.FOLDER_NAME, folderName);
contentResolver.insert(FeedProvider.FOLDERS_URI, folderValues);
if (!existingFolders.contains(folderName)) {
final ContentValues folderValues = new ContentValues();
folderValues.put(DatabaseConstants.FOLDER_NAME, folderName);
contentResolver.insert(FeedProvider.FOLDERS_URI, folderValues);
}
for (Long feedId : entry.getValue()) {
ContentValues values = new ContentValues();
values.put(DatabaseConstants.FEED_FOLDER_FEED_ID, feedId);
values.put(DatabaseConstants.FEED_FOLDER_FOLDER_NAME, folderName);
contentResolver.insert(FeedProvider.FEED_FOLDER_MAP_URI, values);
if (!existingFeeds.containsKey(Long.toString(feedId))) {
ContentValues values = new ContentValues();
values.put(DatabaseConstants.FEED_FOLDER_FEED_ID, feedId);
values.put(DatabaseConstants.FEED_FOLDER_FOLDER_NAME, folderName);
contentResolver.insert(FeedProvider.FEED_FOLDER_MAP_URI, values);
}
}
}
}
}
private HashMap<String, Feed> getExistingFeeds() {
Cursor feedCursor = contentResolver.query(FeedProvider.FEEDS_URI, null, null, null, null);
feedCursor.moveToFirst();
HashMap<String, Feed> existingFeeds = new HashMap<String, Feed>();
while (!feedCursor.isAfterLast()) {
existingFeeds.put(Feed.fromCursor(feedCursor).feedId, Feed.fromCursor(feedCursor));
feedCursor.moveToNext();
}
feedCursor.close();
return existingFeeds;
}
public boolean trainClassifier(String feedId, String key, int type, int action) {
String typeText = null;
String actionText = null;