Skip to content

Instantly share code, notes, and snippets.

View AAverin's full-sized avatar

Anton Averin AAverin

View GitHub Profile
@AAverin
AAverin / ConsistencyManager.kt
Last active October 6, 2017 17:35
A simple consistency manager implementation on Kotlin. You can subscribe on some class changes, and notify subscribers about that class being updated. Convinient when you have data being displayed in many different places and you need it up to date any time it changes, eg. somebody is making item favorite and 'star' icons should update everywhere
interface ConsistencyManagerContract {
fun notifyUpdateModel(model: Any)
fun notifyUpdateClass(kclass: KClass<*>)
fun subscribe(modelClass: KClass<*>, callback: WeakReference<(Any?) -> Unit>)
}
class ConsistencyManager : ConsistencyManagerContract {
private val subscriptionsMap: MutableMap<KClass<*>, MutableList<WeakReference<(Any?) -> Unit>>> = mutableMapOf()
override fun notifyUpdateModel(model: Any) {
@AAverin
AAverin / ConsistencyManager.kt
Created June 13, 2016 13:47
A simple consistency manager implementation on Kotlin.
interface ConsistencyManagerContract {
fun notifyUpdateModel(model: Any)
fun notifyUpdateClass(kclass: KClass<*>)
fun subscribe(modelClass: KClass<*>, callback: WeakReference<(Any?) -> Unit>)
}
class ConsistencyManager : ConsistencyManagerContract {
private val subscriptionsMap: MutableMap<KClass<*>, MutableList<WeakReference<(Any?) -> Unit>>> = mutableMapOf()
override fun notifyUpdateModel(model: Any) {
interface NavigationDrawerViewExtensionDelegate : EventsDelegate {
fun showInitialScreen()
fun showNav1Screen()
fun showNav2Screen()
}
interface NavigationDrawerViewExtensionContract
@ActivityScope
class NavigationDrawerViewExtension @Inject constructor(
public class LI01Fragment extends BaseFragment {
public final static int DISCOUNTED_TAB = 99;
SlidingTabLayout slidingTabs;
ViewPager viewPager;
ArrayList<CarsPagerItem> mTabs;
LinearLayout blankSlate;
DrawerLayout filterDrawer;
ActionBarDrawerToggle drawerToggle;
@RunWith(PowerMockRunner::class)
@PrepareForTest(DrawerToggleFactory::class,
MainPresenter::class)
class NavigationDrawerViewExtensionTest {
@Mock lateinit private var activity: BaseActivity
@Mock lateinit private var drawerToggleFactory: DrawerToggleFactory
@Mock lateinit private var eventsDelegate: NavigationDrawerViewExtensionDelegate
@Mock lateinit private var toolbar: Toolbar
//Implement this interface in classes that can handle events
public interface HasRxBusEvent {
void onEvent(RxBusEvent event);
}
@AAverin
AAverin / sharelogcat.java
Created November 24, 2015 17:44
Share logcat for Android
public void shareLogcat() {
String sdcardPath = null;
String path = Environment.getExternalStorageDirectory() + "/my_application_folder";
File dir = new File(path);
if (dir.mkdirs() || dir.isDirectory()) {
sdcardPath = path + File.separator + "logcat_" + System.currentTimeMillis() + ".log";
}
if (sdcardPath == null) {
return;
@AAverin
AAverin / gist:e3d293ca168b53443773
Created November 23, 2015 14:43
Xcode crash on breakpoint
Process: Xcode [42461]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 7.0.1 (8228)
Build Info: IDEFrameworks-8228000000000000~5
App Item ID: 497799835
App External ID: 813434267
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [42461]
@AAverin
AAverin / proguard.config
Created December 8, 2014 09:06
OpenScienceMap VTM proguard configuration
-printusage unused.txt
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-printmapping out.map
-dontpreverify
@AAverin
AAverin / ExtendedMapView.java
Last active August 29, 2015 14:09
OpenScienceMap ExtendedMapView. Uses my custom preferences cache wrapper, just use your own implementation
public class ExtendedMapView extends MapView {
private BaseContext baseContext;
public ExtendedMapView(Context context) {
super(context);
baseContext = (BaseContext) context.getApplicationContext();
restorePosition();
}