@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.post); Collection<Account> accounts; Config conf; try { this.prefs = new Prefs(getBaseContext()); accounts = this.prefs.readAccounts(); conf = this.prefs.asConfig(); } catch (Exception e) { // No point continuing if any exception. DialogHelper.alertAndClose(this, e); return; } this.imageCache = new HybridBitmapCache(getBaseContext(), C.MAX_MEMORY_IMAGE_CACHE); this.exec = ExecUtils.newBoundedCachedThreadPool(C.IMAGE_LOADER_MAX_THREADS, LOG); this.intentExtras = getIntent().getExtras(); this.inReplyToUid = this.intentExtras.getLong(ARG_IN_REPLY_TO_UID); this.inReplyToSid = this.intentExtras.getString(ARG_IN_REPLY_TO_SID); this.alsoMentions = this.intentExtras.getStringArray(ARG_ALSO_MENTIONS); LOG.i( "inReplyToUid=%d inReplyToSid=%s alsoMentions=%s", this.inReplyToUid, this.inReplyToSid, Arrays.toString(this.alsoMentions)); setupAccounts(savedInstanceState, accounts, conf); setupAttachemnt(savedInstanceState); setupTextBody(); wireMainButtons(); }
protected void showInReplyToTweetDetails() { Tweet tweet = null; if (this.inReplyToSid != null && this.inReplyToUid > 0L) { final View view = findViewById(R.id.tweetReplyToDetails); view.setVisibility(View.VISIBLE); tweet = getDb().getTweetDetails(this.inReplyToUid); if (tweet != null) { LOG.i("inReplyTo:%s", tweet.toFullString()); if (!this.enabledPostToAccounts.isServicesPreSpecified()) { final Meta serviceMeta = tweet.getFirstMetaOfType(MetaType.SERVICE); if (serviceMeta != null) setPostToAccountExclusive(ServiceRef.parseServiceMeta(serviceMeta)); } ((TextView) view.findViewById(R.id.tweetDetailBody)).setText(tweet.getBody()); if (tweet.getAvatarUrl() != null) loadImage( new ImageLoadRequest( tweet.getAvatarUrl(), (ImageView) view.findViewById(R.id.tweetDetailAvatar))); ((TextView) view.findViewById(R.id.tweetDetailName)).setText(tweet.getFullname()); ((TextView) view.findViewById(R.id.tweetDetailDate)) .setText( DateFormat.getDateTimeInstance() .format(new Date(TimeUnit.SECONDS.toMillis(tweet.getTime())))); } } initBody(tweet); this.txtBody.setSelection(this.txtBody.getText().length()); }
private void setupAccounts( final Bundle savedInstanceState, final Collection<Account> accounts, final Config conf) { String accountId = null; Account account = null; if (savedInstanceState != null) accountId = savedInstanceState.getString(ARG_ACCOUNT_ID); if (accountId == null) accountId = this.intentExtras.getString(ARG_ACCOUNT_ID); if (accountId != null) { account = conf.getAccount(accountId); final List<String> svcs = this.intentExtras.getStringArrayList(ARG_SVCS); LOG.i("accountId=%s svcs=%s", account.getId(), svcs); this.enabledPostToAccounts.setAccount(account); this.enabledPostToAccounts.fromBundle(savedInstanceState); if (svcs != null && !this.enabledPostToAccounts.isServicesPreSpecified()) { for (String svc : svcs) { this.enabledPostToAccounts.enable(ServiceRef.parseServiceMeta(svc)); } this.enabledPostToAccounts.setServicesPreSpecified(true); } } else { this.askAccountOnActivate = true; } this.spnAccount = (Spinner) findViewById(R.id.spnAccount); this.accountAdaptor = new AccountAdaptor(getBaseContext(), accounts); this.spnAccount.setAdapter(this.accountAdaptor); setSelectedAccount(account); this.spnAccount.setOnItemSelectedListener(this.accountOnItemSelectedListener); this.llSubAccounts = (ViewGroup) findViewById(R.id.llSubAccounts); }
private void resumeDb() { if (this.bndDb == null) { LOG.d("Binding DB service..."); this.bndDb = new DbClient( this, LOG.getPrefix(), new Runnable() { @Override public void run() { LOG.d("DB service bound."); showInReplyToTweetDetails(); } }); } }
private void storeResult( final DbInterface db, final int pushedCount, final int pulledCount, final Exception e) { final String status; if (e != null) { status = String.format("Failed: %s", ExcpetionHelper.causeTrace(e)); // ES LOG.w(status); } else { status = String.format( "Success: pushed %s and pulled %s columns.", pushedCount, pulledCount); // ES } db.storeValue( KvKeys.KEY_HOSAKA_STATUS, String.format( "%s %s", DateHelper.formatDateTime(this, System.currentTimeMillis()), status)); }
@Override protected void doWork(final Intent i) { final Prefs prefs = new Prefs(getBaseContext()); final Config conf; try { conf = prefs.asConfig(); } catch (final JSONException e) { LOG.w("Can not send to Hosaka: %s", e.toString()); return; } // XXX Currently this assumes only one Hosaka account. // TODO Make UI stop user adding more than one Hosaka account. final Account account = conf.firstAccountOfType(AccountProvider.HOSAKA); if (account == null) { LOG.i("Not sending to Hosaka: no account found."); return; } if (!waitForDbReady()) return; final DbInterface db = getDb(); SaveScrollNow.requestAndWaitForUiToSaveScroll(db); final Map<String, Column> hashToCol = new HashMap<String, Column>(); final Map<String, HosakaColumn> toPush = new HashMap<String, HosakaColumn>(); for (final Column col : conf.getColumns()) { if (InternalColumnType.fromColumn(col) != null) continue; // Do not sync internal columns. final String hash = HosakaColumn.columnHash(col, conf); hashToCol.put(hash, col); final ScrollState ss = db.getScroll(col.getId()); if (ss == null) continue; // In case of (new) empty columns. // Always add all columns, even if sent before new values. // - Old / regressed values will be filtered server side. // - Values sent can be used to filter response. // - Also useful as do not know state of remote DB. toPush.put( hash, new HosakaColumn( null /* ss.getItemId(); TODO ScrollState to also store sid? */, ss.getItemTime(), ss.getUnreadTime(), ss.getScrollDirection())); } final HosakaProvider prov = new HosakaProvider(); try { // Make POST even if not really sending anything new, as may be fetching new state. final long startTime = now(); final Map<String, HosakaColumn> returnedColumns = prov.sendColumns(account, toPush); final long durationMillis = TimeUnit.NANOSECONDS.toMillis(now() - startTime); LOG.i("Sent %s in %d millis: %s", account.getAccessToken(), durationMillis, toPush); final boolean syncScroll = prefs.getSharedPreferences().getBoolean(FetchingPrefFragment.KEY_SYNC_SCROLL, false); final Map<Column, ScrollState> colToNewScroll = new HashMap<Column, ScrollState>(); for (final Entry<String, HosakaColumn> e : returnedColumns.entrySet()) { final String hash = e.getKey(); final Column col = hashToCol.get(hash); final HosakaColumn before = toPush.get(hash); final HosakaColumn after = e.getValue(); if (col != null && before != null && (after.getUnreadTime() > before.getUnreadTime() || (syncScroll && before.getScrollDirection() == ScrollDirection.UP && after.getItemTime() > before.getItemTime()))) { colToNewScroll.put(col, after.toScrollState()); } } db.mergeAndStoreScrolls( colToNewScroll, syncScroll ? ScrollChangeType.UNREAD_AND_SCROLL : ScrollChangeType.UNREAD); LOG.i("Merged %s columns: %s.", colToNewScroll.size(), colToNewScroll); storeResult(db, toPush.size(), colToNewScroll.size(), null); } catch (final IOException e) { storeResult(db, toPush.size(), 0, e); } catch (final JSONException e) { storeResult(db, toPush.size(), 0, e); } finally { prov.shutdown(); } }
private void setPostToAccountExclusive(final ServiceRef svc) { if (svc == null) return; LOG.d("setPostToAccountExclusive(%s)", svc); this.enabledPostToAccounts.enableExclusiveAndSetPreSpecified(svc); PostToAccountLoaderTask.setAccountBtns(this.llSubAccounts, this.enabledPostToAccounts); }