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 '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', |
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 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; | |
} |
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 interface TownshipListView extends LoadDataView { | |
void renderTownshipList(List<TownshipModel> townshipModels); | |
} | |
public interface LoadDataView { | |
void showLoading(); | |
void hideLoading(); | |
void showError(String errorMessage); | |
Context context(); | |
} |
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 interface TownshipListView extends LoadDataView { | |
void renderTownshipList(List<TownshipModel> townshipModels); | |
} |
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 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>>() { |
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 interface TownshipRepository { | |
Observable<List<Township>> townships(); | |
} |
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 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; |
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 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{ |
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 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 |
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 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(); | |
} |
NewerOlder