This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pl.brightinventions.samples; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
import javax.inject.Singleton; | |
public interface CurrentUserProvider { | |
boolean isLoggedIn(); | |
CurrentUser getCurrentUser(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum UserType { | |
ANONYMOUS, | |
REGULAR, | |
PREMIUM | |
} | |
class MyActivity extends Activity { | |
@Inject | |
CurrentUserProvider _userProvider; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface UserReference { | |
void dispatchBehavior(@NonNull UserBehavior behavior); | |
} | |
class AnonymousUserReference implements UserReference { | |
@Override | |
public void dispatchBehavior(@NonNull UserBehavior behavior) { | |
behavior.onAnonymous(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class UserBehavior { | |
private boolean shouldRunDefault; | |
public void byDefault(UserReference reference){} | |
public void onAnonymous(UserReference user){ | |
shouldRunDefault = true; | |
} | |
public void onRegular(RegularUserReference user) { | |
shouldRunDefault = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Action2<T,Throwable> { | |
void call(T t, Throwable error); | |
} | |
interface RegisterApi { | |
class RegistrationModel { | |
String firstName; | |
} | |
void register(RegistrationModel data, Action2<RegistrationModel, Throwable> result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pl.brightinventions.databinding.databinding.ActivityRegisterBinding; | |
public class RegisterActivity extends Activity { | |
RegisterApi registerApi; // inject or create remote api | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActivityRegisterBinding viewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_register); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": { | |
"Service": "ec2.amazonaws.com" | |
}, | |
"Action": "sts:AssumeRole" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PageAppearanceSection : ConfigurationSection<IPageAppearance> | |
{ | |
} | |
public interface IPageAppearance | |
{ | |
bool RemoteOnly { get; } | |
IFont Font { get; } | |
IColor Color { get; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetrofitTest { | |
@Test | |
public void configure() throws Exception { | |
ObjectMapper mapper = new ObjectMapper(); | |
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | |
mapper.registerModule(new JodaModule()); | |
Retrofit retrofit = new Retrofit.Builder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.stackanswers; | |
import android.app.Activity | |
import org.junit.Assert | |
import org.junit.Before; | |
import org.junit.Rule | |
import org.junit.Test | |
import org.junit.runner.RunWith; | |
import org.mockito.* | |
import org.mockito.junit.MockitoJUnit |