Skip to content

Instantly share code, notes, and snippets.

View osama's full-sized avatar

Muhammad Osama osama

View GitHub Profile
@osama
osama / HomeController.kt
Created May 21, 2020 21:24
Server-Driven UI Blog
class HomeController(
val onSmallNavigationClick: (SmallNavigationSection, Int) -> Unit,
) : PagedListEpoxyController<HomeSection>() {
override fun buildItemModel(
currentPosition: Int,
item: HomeSection?
): EpoxyModel<*> = when (item) {
is SmallNavigationSection -> buildSmallNav(
item,
@osama
osama / HomeApiParser.kt
Created May 21, 2020 21:23
Server-Driven UI Blog
private fun section(obj: JSONObject): HomeSection? {
val serverType = obj.getString("type")
val serverData = obj.optJSONObject("data") ?: return null
val type = HomeSection.UiType.fromString(serverType) ?: return null
val adapter = moshi.adapter(type.toClass().java)
return try {
val section = adapter.fromJson(serverData.toString())
if (section?.type != type) {
@osama
osama / SmallNavigationSection.kt
Created May 21, 2020 21:21
Server-Driven UI Blog
interface HomeSection {
val type: UiType
val id: String
enum class UiType(val serverName: String) {
SMALL_NAVIGATION("smallNavigation");
fun toClass(): KClass<out HomeSection> = when (this) {
SMALL_NAVIGATION -> SmallNavigationSection::class
@osama
osama / small_navigation.json
Created May 21, 2020 21:17
Server-Driven UI Blog
{
"sections":[
{
"type":"smallNavigation",
"data":{
"heading":"Separate fact from fiction",
"subheading":"Access the latest on COVID-19 from these credible sources.",
"image":"https://a.wattpad.com/image/smallnav_covid_information_large.png",
"weblink":"https://support.wattpad.com/hc/en-us/articles/360040903132"
}
@osama
osama / scifi_server_driven.json
Created May 21, 2020 20:12
Server-Driven UI Blog
{
"type":"storyList",
"data":{
"heading":"Science Fiction and Fantasy",
"items":[
{
"title":"The Ants that Carried Us",
"cover":"https://a.wattpad.com/cover/185650009-256-k836366.jpg",
"tag":"empire"
}
@osama
osama / scifi_traditional.json
Created May 21, 2020 19:49
Server-Driven UI Blog
{
"type":"scifiRow",
"stories":[
{
"id":"1234",
"title":"The Ants that Carried Us",
"description":"They say that the two things Shah Minos loves most are fire and spies...",
"cover":"https://a.wattpad.com/cover/185650009-256-k836366.jpg",
"tags":[
"action",
@osama
osama / HomeApiParser.kt
Last active April 29, 2020 17:03
Server-Driven UI Blog
private fun section(obj: JSONObject): HomeSection? {
val serverType = obj.getString("type")
val serverData = obj.optJSONObject("data") ?: return null
val type = HomeSection.UiType.fromString(serverType) ?: return null
val adapter = moshi.adapter(type.toClass().java)
return try {
val section = adapter.fromJson(serverData.toString())
if (section?.type != type) {
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.view.Gravity;
import android.view.View;
@osama
osama / jarBuilder.bat
Created March 13, 2015 04:41
Windows Batchfile for Compiling JARs
@echo off
TITLE JAR Builder by Muhammad Osama
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
set /p mainc=Enter name of the class that includes your main method (do not include .class) :
set /p yname=Enter author's name :
echo Main-Class: %mainc%%NL%>manifest.txt