Skip to content

Commit

Permalink
#384 Fixed syncing combined timelines and Public timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Jun 26, 2016
1 parent bb1972c commit 77c8844
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 172 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/org/andstatus/app/data/ParsedUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public UserListType getUserListType() {
public long getOriginId() {
long originId = 0;
try {
originId = Long.parseLong(uri.getPathSegments().get(5));
if (uri.getPathSegments().size() > 4) {
originId = Long.parseLong(uri.getPathSegments().get(5));
}
} catch (Exception e) {
MyLog.d(this, toString(), e);
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/org/andstatus/app/msg/TimelineActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,14 @@ private void launchSyncIfNeeded(Timeline timelineToSync) {
}

protected void syncWithInternet(Timeline timelineToSync, boolean manuallyLaunched) {
if (getParamsNew().isTimelineCombined() && timelineToSync.getTimelineType().canBeCombinedForOrigins()) {
if (timelineToSync.canBeSyncedForOrigins()) {
syncForAllOrigins(timelineToSync, manuallyLaunched);
} else if (getParamsNew().isTimelineCombined() && timelineToSync.getTimelineType().canBeCombinedForMyAccounts()) {
} else if (timelineToSync.canBeSyncedForAccounts()) {
syncForAllAccounts(timelineToSync, manuallyLaunched);
} else {
} else if (timelineToSync.canBeSynced()) {
syncOneTimeline(timelineToSync, manuallyLaunched);
} else {
hideSyncing("SyncWithInternet");
}
}

Expand All @@ -892,7 +894,7 @@ private void syncForAllAccounts(Timeline timelineToSync, boolean manuallyLaunche

private void syncOneTimeline(Timeline timeline, boolean manuallyLaunched) {
final String method = "syncOneTimeline";
if (timeline.getMyAccount().isValidAndSucceeded() && timeline.getTimelineType().canBeSynced() ) {
if (timeline.canBeSynced()) {
setCircularSyncIndicator(method, true);
showSyncing(method, getText(R.string.options_menu_sync));
MyServiceManager.sendForegroundCommand(
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/andstatus/app/origin/PersistentOrigins.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.andstatus.app.context.MyContextImpl;
import org.andstatus.app.data.DbUtils;
import org.andstatus.app.database.OriginTable;
import org.andstatus.app.timeline.TimelineType;
import org.andstatus.app.util.MyLog;

import java.util.ArrayList;
Expand Down Expand Up @@ -169,4 +170,14 @@ public List<Origin> originsForGlobalSearch(Origin originIn, boolean forAllOrigin
}
return origins;
}

// TODO: implement
public boolean canBeSynced(TimelineType timelineType, long originId) {
switch (timelineType) {
case PUBLIC:
return true;
default:
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.text.TextUtils;

import org.andstatus.app.context.MyContextHolder;
import org.andstatus.app.timeline.TimelineType;
import org.andstatus.app.net.http.ConnectionException;
import org.andstatus.app.util.MyLog;
import org.andstatus.app.util.RelativeTime;
Expand Down Expand Up @@ -97,14 +96,14 @@ static CommandExecutorStrategy getStrategy(CommandExecutionContext execContext)
if (execContext.getMyAccount().isValidAndSucceeded()) {
switch (execContext.getCommandData().getCommand()) {
case FETCH_TIMELINE:
if (execContext.getCommandData().getTimeline().isSyncable()) {
if (execContext.getCommandData().getTimeline().canBeSynced()) {
strategy = new CommandExecutorLoadTimeline();
} else {
strategy = new CommandExecutorStrategy();
}
break;
case SEARCH_MESSAGE:
if (execContext.getCommandData().getTimeline().isSyncable()) {
if (execContext.getCommandData().getTimeline().canBeSynced()) {
strategy = new CommandExecutorSearch();
} else {
strategy = new CommandExecutorStrategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.andstatus.app.data.OidEnum;
import org.andstatus.app.net.http.ConnectionException;
import org.andstatus.app.net.http.ConnectionException.StatusCode;
import org.andstatus.app.net.social.Connection;
import org.andstatus.app.net.social.MbTimelineItem;
import org.andstatus.app.net.social.TimelinePosition;
import org.andstatus.app.timeline.LatestTimelineItem;
Expand All @@ -41,8 +40,8 @@ class TimelineDownloaderOther extends TimelineDownloader {

@Override
public void download() throws ConnectionException {
if (!getTimeline().isSyncable()) {
throw new IllegalArgumentException("Invalid Timeline for download: " + getTimeline());
if (!getTimeline().canBeSynced()) {
throw new IllegalArgumentException("Timeline cannot be synced: " + getTimeline());
}

LatestTimelineItem latestTimelineItem = new LatestTimelineItem(getTimeline());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void onPerformSync(Account account, Bundle extras, String authority,
if (!MyServiceManager.isServiceAvailable()) {
MyLog.d(this, account.name + " Service unavailable");
syncResult.stats.numIoExceptions++;
return;
}

new MyServiceCommandsRunner(MyContextHolder.initialize(mContext, this)).
Expand Down

0 comments on commit 77c8844

Please sign in to comment.