Skip to content

Instantly share code, notes, and snippets.

View matdziu's full-sized avatar

Mateusz Dziubek matdziu

View GitHub Profile
public class OnlineCacheInterceptor implements Interceptor {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Response response = chain.proceed(chain.request());
CacheControl cacheControl = new CacheControl.Builder()
.maxAge(30, TimeUnit.SECONDS)
.build();
return response.newBuilder()
.header("Cache-Control", cacheControl.toString())
public class OfflineCacheInterceptor implements Interceptor {
private boolean isOnline;
public OfflineCacheInterceptor(boolean isOnline) {
this.isOnline = isOnline;
}
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
public class DataDeserializerTest extends BaseDeserializerTest {
private Gson gson;
@Before
public void setUp() {
gson = new GsonBuilder()
.registerTypeAdapter(DataModel.class, new DataDeserializer())
.create();
}
public interface RowType {}
public class ButtonRowType implements RowType {
private Context context;
public ButtonRowType(Context context) {
this.context = context;
}
public View.OnClickListener getOnClickListener() {
return new View.OnClickListener() {
public class ImageRowType implements RowType {
private String text;
public ImageRowType(String text) {
this.text = text;
}
public String getText() {
return text;
public class TextRowType implements RowType {
private String header;
private String text;
public TextRowType(String header, String text) {
this.header = header;
this.text = text;
}
public interface RowType {
int BUTTON_ROW_TYPE = 0;
int IMAGE_ROW_TYPE = 1;
int TEXT_ROW_TYPE = 2;
}
public class MultipleTypesAdapter extends RecyclerView.Adapter {
private List<RowType> dataSet;
public MultipleTypesAdapter(List<RowType> dataSet) {
this.dataSet = dataSet;
}
@Override
public int getItemViewType(int position) {
public class ViewHolderFactory {
public static class ButtonViewHolder extends RecyclerView.ViewHolder {
public Button button;
public ButtonViewHolder(View itemView) {
super(itemView);
button = (Button) itemView.findViewById(R.id.button);
}