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
class MainActivity : AppCompatActivity() { | |
private var toolBar: Toolbar? = null | |
private var container: ViewGroup? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
coordinatorLayout { | |
fitsSystemWindows = true | |
appBarLayout { |
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 ViewBinder<in T> { | |
fun bind(t: T) : View | |
fun unbind(t: T) | |
} |
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
class MainLayout : ViewBinder<MainActivity> { | |
override fun bind(mainActivity: MainActivity): View = | |
mainActivity.UI { | |
coordinatorLayout { | |
fitsSystemWindows = true | |
appBarLayout { | |
mainActivity.toolBar = toolbar { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) elevation = 4f |
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
configuration(orientation = Orientation.LANDSCAPE, smallestWidth = 700) { | |
recyclerView { | |
init() | |
}.lparams(width = widthProcent(50), height = matchParent) | |
frameLayout().lparams(width = matchParent, height = matchParent) | |
} | |
fun <T : View> T.widthProcent(procent: Int): Int = | |
getAppUseableScreenSize().x.toFloat().times(procent.toFloat() / 100).toInt() |
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 MainActivity extends AppCompatActivity { | |
LinearLayout container; | |
RecyclerView recycView; | |
FrameLayout detailContainer; | |
private MainLayout mainLayout = new MainLayout(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { |
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
sealed class MathExpression | |
data class Add(val left: MathExpression, val right: MathExpression) : MathExpression() | |
data class Sub(val left: MathExpression, val right: MathExpression) : MathExpression() | |
data class Number(val value: Int): MathExpression() |
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
sealed class MathExpression { | |
abstract fun eval(): Int | |
} | |
data class Addition(val left: MathExpression, val right: MathExpression) : MathExpression() { | |
override fun eval(): Int = left.eval() + right.eval() | |
} | |
data class Subtraction(val left: MathExpression, val right: MathExpression) : MathExpression() { | |
override fun eval(): Int = left.eval() - right.eval() |
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
sealed class MathExpression { | |
fun eval(): Int = when(this) { | |
is Addition -> left.eval() + right.eval() | |
is Subtraction -> left.eval() - right.eval() | |
is Number -> value | |
} | |
} | |
data class Addition(val left: MathExpression, val right: MathExpression) : MathExpression() | |
data class Subtraction(val left: MathExpression, val right: MathExpression) : MathExpression() |
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
╔═══════════════════╦═════════════════════════╦═════════════════════════╗ | |
║ ║ Add new method ║ Add new data ║ | |
╠═══════════════════╬═════════════════════════╬═════════════════════════╣ | |
║ Polymorpish ║ Change existing code ║ Existing code unchanged ║ | |
║ Pattern matching ║ Existing code unchanged ║ Change existing code ║ | |
╚═══════════════════╩═════════════════════════╩═════════════════════════╝ |
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
sealed class MathExpression { | |
fun eval(): Int = when (this) { | |
is Addition -> left.eval() + right.eval() | |
is Subtraction -> left.eval() - right.eval() | |
is Division -> left.eval() / right.eval() | |
is Number -> value | |
} | |
} | |
data class Addition(val left: MathExpression, val right: MathExpression) : MathExpression() |
OlderNewer