Skip to content

Instantly share code, notes, and snippets.

View scottroemeschke's full-sized avatar

Scott Roe-Meschke scottroemeschke

  • Snap
  • Denver, Colorado
View GitHub Profile
@scottroemeschke
scottroemeschke / EditPostActivity2.java
Last active July 6, 2016 00:40
Example IntentBuilder usage (Decompile Deep Dive: Medium)
public static Intent createIntent(Context paramContext) {
return IntentBuilder.forActivity(paramContext, EditPostActivity2.class).build();
}
public static Intent createIntent(Context paramContext, String paramString, SelectionProtos.SelectionPb paramSelectionPb) {
return IntentBuilder.forActivity(paramContext, EditPostActivity2.class).withParam("postId", paramString).withJsonExtra("initialSelection", paramSelectionPb).build();
}
public static Intent createIntentForQuoteResponse(Context paramContext, QuoteProtos.Quote paramQuote) {
return IntentBuilder.forActivity(paramContext, EditPostActivity2.class).withJsonExtra("inResponseToQuote", paramQuote).build();
@scottroemeschke
scottroemeschke / IntentBuilder.java
Last active July 6, 2016 00:40
Intent Builder - Entry Points (Decompile-Deepdive: Medium)
private IntentBuilder(Context paramContext, Class<?> paramClass) {
intent = new Intent(paramContext, paramClass);
res = paramContext.getResources();
component = paramClass;
}
public static IntentBuilder forActivity(Context paramContext, Class<? extends MediumActivity> paramClass) {
return new IntentBuilder(paramContext, paramClass);
}
@scottroemeschke
scottroemeschke / IntentBuilder.java
Last active July 6, 2016 00:40
IntentBuilder-withAction (Decompile-Deepdive: Medium)
private Optional<Enum> maybeAction = Optional.absent();
public IntentBuilder withAction(Enum paramEnum) {
maybeAction = Optional.of(paramEnum);
return this;
}
@scottroemeschke
scottroemeschke / IntentBuilder.java
Last active July 20, 2016 10:22
IntentBuilder- Extras (Decompile-Deepdive: Medium)
public IntentBuilder withExtra(String paramString, String[] paramArrayOfString) {
intent.putExtra(paramString, paramArrayOfString);
return this;
}
public IntentBuilder withJsonExtra(String paramString, JsonSerializable paramJsonSerializable) {
try {
intent.putExtra(paramString, mapper.writeValueAsString(paramJsonSerializable));
return this;
} catch (JsonProcessingException paramJsonSerializable) {
@scottroemeschke
scottroemeschke / IntentBuilder.java
Last active July 6, 2016 00:39
IntentBuilder-Uri Handling (Decompile-Deepdive: Medium)
private final Uri.Builder dataBuilder = new Uri.Builder(); //android.net.Uri.Builder
public IntentBuilder withParam(String paramString, int paramInt) {
dataBuilder.appendQueryParameter(paramString, Integer.toString(paramInt));
return this;
}
public IntentBuilder withParam(String paramString, long paramLong) {
dataBuilder.appendQueryParameter(paramString, Long.toString(paramLong));
return this;
@scottroemeschke
scottroemeschke / IntentBuilder.java
Created July 6, 2016 00:38
IntentBuilder - Build Method
public Intent build() {
Object localObject = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, component.getSimpleName());
dataBuilder.scheme(res.getString(R.string.some_string)).authority((String) localObject);
if (maybeAction.isPresent()) {
localObject = (Enum) maybeAction.get();
dataBuilder.fragment(((Enum) localObject).name());
intent.setAction(localObject.getClass().getName() + "." + ((Enum) localObject).name());
}
intent.setData(this.dataBuilder.build());
return intent;
@scottroemeschke
scottroemeschke / CreateAccountActivity.java
Created July 6, 2016 00:42
Example Intent Builder Usage 2
public static Intent createIntent(Context paramContext, AuthCredential paramAuthCredential, Optional<RegistrationData> paramOptional, boolean paramBoolean) {
return IntentBuilder.forActivity(paramContext, CreateAccountActivity.class).withSerializableExtra("authCredential", (Serializable) Preconditions.checkNotNull(paramAuthCredential)).withJsonExtra("registrationData", (JsonSerializable) paramOptional.orNull()).withParam("isOnboarded", paramBoolean).build();
}
@scottroemeschke
scottroemeschke / AccessCredentialStore.java
Created July 6, 2016 00:47
Example Optional Usage (Decompile-Deepdive: Medium)
public class AccessCredentialStore {
//... a bunch of fields...
Optional<AccessCredential> credential;
Optional<UserProtos.User> currentUser;
//... a bunch more fields...
public Optional<AccessCredential> loadCredential();
public Optional<UserProtos.User> getCurrentUser();
}
@scottroemeschke
scottroemeschke / AbstractMediumActivity.java
Created July 6, 2016 01:28
Optional Usage 2 (Decompile-Deepdive: Medium)
public abstract class AbstractMediumActivity<APP_COMPONENT> extends AppCompatActivity implements MediumActivity {
AuthChecker authChecker;
boolean enableCrashlytics;
MediumActivity.FailureDispatcher failureDispatcher;
Uri referrerBaseUri;
RxRegistry rxRegistry;
Optional<MediumTheme> themeOnCreation;
Provider<Optional<MediumTheme>> themeProvider;
Tracker tracker;
}
@scottroemeschke
scottroemeschke / DetailPresenter.java
Created July 24, 2016 21:02
Constructor and Class Definition
public abstract class DetailPresenter
implements TalkActionFactory.Callback, DetailActionRow.OnClickListener,
DownloadDialog.DownloadDialogListener, DownloadController.DownloadUICallback, TalkActionFactory.SectionCallback {
public DetailPresenter(Context context, DetailListFactory detailListFactory, StoreFavorites storeFavorites,
UpdateDownloads updateDownloads, StoreQueue storeQueue, GetDownloads getDownloads, Tracker tracker, StoreHistory storeHistory) {
this.context = context;
this.detailListFactory = detailListFactory;
this.downloadController = new DownloadController(context, updateDownloads, getDownloads, this);
this.storeFavorites = storeFavorites;