Skip to content

Instantly share code, notes, and snippets.

View yemyatthu1990's full-sized avatar

Ye Myat Thu yemyatthu1990

  • Shield.com
  • Yangon
View GitHub Profile
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
public class TownshipListPresenter implements Presenter{
private TownshipListView townshipListView;
private final GetTownshipList getTownshipList;
private final TownshipModelMapper townshipModelMapper;
public TownshipListPresenter(GetTownshipList getTownshipList,TownshipModelMapper townshipModelMapper){
this.getTownshipList = getTownshipList;
this.townshipModelMapper = townshipModelMapper;
}
public interface TownshipListView extends LoadDataView {
void renderTownshipList(List<TownshipModel> townshipModels);
}
public interface LoadDataView {
void showLoading();
void hideLoading();
void showError(String errorMessage);
Context context();
}
public interface TownshipListView extends LoadDataView {
void renderTownshipList(List<TownshipModel> townshipModels);
}
public class TownshipDataRepository implements TownshipRepository{
private final TownshipDataStoreFactory townshipDataStoreFactory;
private final TownshipMapper townshipMapper;
public TownshipDataRepository(TownshipDataStoreFactory townshipDataStoreFactory,TownshipMapper townshipMapper){
this.townshipDataStoreFactory = townshipDataStoreFactory;
this.townshipMapper = townshipMapper;
}
@Override
public Observable<List<Township>> townships() {
return townshipDataStoreFactory.create().townships().map(new Function<List<TownshipEntity>, List<Township>>() {
public interface TownshipRepository {
Observable<List<Township>> townships();
}
public class TownshipCacheImpl implements TownshipCache {
private static final long EXPIRATION_TIME = 60 * 10 * 1000;
@Override
public boolean isExpired() {
Realm realm = Realm.getDefaultInstance();
if (realm.where(TownshipEntity.class).count() != 0) {
Date currentTime = new Date(System.currentTimeMillis());
SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);
Date lastUpdated = null;
public class TownshipDataStoreFactory {
private final TownshipCache townshipCache;
public TownshipDataStoreFactory(TownshipCache townshipCache){
this.townshipCache = townshipCache;
}
public TownshipDataStore create(){
if(!townshipCache.isExpired() && townshipCache.isCached()){
return new TownshipLocalDataStore(townshipCache);
}else{
public class TownshipCloudDataStore implements TownshipDataStore {
private final TownshipCache townshipCache;
TownshipCloudDataStore(TownshipCache townshipCache){
this.townshipCache = townshipCache;
}
@Override
public Observable<List<TownshipEntity>> townships() {
return ServiceGenerator.getTownshipService().getTownships().doOnNext(new Consumer<List<TownshipEntity>>() {
@Override
public class TownshipLocalDataStore implements TownshipDataStore {
private final TownshipCache townshipCache;
TownshipLocalDataStore(TownshipCache townshipCache){
this.townshipCache = townshipCache;
}
//Return a list of townships from DB
@Override
public Observable<List<TownshipEntity>> townships() {
return townshipCache.get();
}