Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}

android {
compileSdkVersion 29
compileSdkVersion 30

defaultConfig {
applicationId "com.sudo.rizwan.twitterclone"
minSdkVersion 23
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand All @@ -31,7 +30,8 @@ android {
jvmTarget = '1.8'
}
composeOptions {
kotlinCompilerExtensionVersion "$compose_compiler_extension_version"
kotlinCompilerVersion kotlin_version
kotlinCompilerExtensionVersion compose_version
}
buildFeatures {
compose true
Expand All @@ -40,17 +40,22 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'

implementation "androidx.ui:ui-foundation:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
implementation 'androidx.activity:activity-compose:1.3.0-alpha03'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"

implementation "androidx.ui:ui-layout:$compose_version"
implementation "androidx.ui:ui-material:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02'

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha03'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
34 changes: 22 additions & 12 deletions app/src/main/java/com/sudo/rizwan/twitterclone/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
package com.sudo.rizwan.twitterclone

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Composable
import androidx.ui.animation.Crossfade
import androidx.ui.core.setContent
import androidx.ui.material.MaterialTheme
import androidx.ui.material.Surface
import com.sudo.rizwan.twitterclone.ui.home.Home
import com.sudo.rizwan.twitterclone.ui.profile.Profile
import com.sudo.rizwan.twitterclone.state.AppState
import androidx.compose.animation.Crossfade
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.lifecycle.viewmodel.compose.viewModel
import com.sudo.rizwan.twitterclone.state.AppStateViewModel
import com.sudo.rizwan.twitterclone.state.Screen
import com.sudo.rizwan.twitterclone.ui.compose.ComposeTweet
import com.sudo.rizwan.twitterclone.ui.home.Home
import com.sudo.rizwan.twitterclone.ui.profile.Profile

class MainActivity : AppCompatActivity() {
private val appState by viewModels<AppStateViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme(colors = AppState.theme) {
val theme = appState.theme.observeAsState(lightThemeColors)

MaterialTheme(colors = theme.value) {
AppContent()
}
}
}

override fun onBackPressed() {
if (AppState.currentScreen !is Screen.Home) {
if (appState.currentScreen.value !is Screen.Home) {
// Temp handling of back navigation
AppState.currentScreen = Screen.Home
appState.currentScreen.value = Screen.Home
return
}
super.onBackPressed()
Expand All @@ -35,7 +42,10 @@ class MainActivity : AppCompatActivity() {

@Composable
fun AppContent() {
Crossfade(AppState.currentScreen) { screen ->
val appState = viewModel<AppStateViewModel>()
val currentScreen = appState.currentScreen.observeAsState(Screen.Home)

Crossfade(currentScreen.value) { screen ->
Surface(color = MaterialTheme.colors.background) {
when (screen) {
is Screen.Home -> Home()
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/sudo/rizwan/twitterclone/Themes.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.sudo.rizwan.twitterclone

import androidx.ui.graphics.Color
import androidx.ui.material.darkColorPalette
import androidx.ui.material.lightColorPalette
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.ui.graphics.Color

private val lightBackgroundColor = Color.White
private val darkBackgroundColor = Color(0xFF15202b)
private val darkerBackgroundColor = Color(0xFF0a0a0a)
private val primaryColor = Color(0xFF08a0e9)

val lightThemeColors = lightColorPalette(
val lightThemeColors = lightColors(
primary = primaryColor,
background = lightBackgroundColor,
surface = lightBackgroundColor
)

val darkThemeColors = darkColorPalette(
val darkThemeColors = darkColors(
primary = primaryColor,
background = darkBackgroundColor,
surface = darkBackgroundColor
)

val darkerThemeColors = darkColorPalette(
val darkerThemeColors = darkColors(
primary = primaryColor,
background = darkerBackgroundColor,
surface = darkerBackgroundColor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.sudo.rizwan.twitterclone.models

import androidx.compose.Model
//import androidx.compose.Model
import java.util.*

@Model
// TODO @Model
data class Tweet(
val user: User,
val tweet: String,
Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/com/sudo/rizwan/twitterclone/state/AppState.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sudo.rizwan.twitterclone.state

import androidx.compose.Model
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sudo.rizwan.twitterclone.lightThemeColors
import com.sudo.rizwan.twitterclone.models.User

Expand All @@ -10,16 +11,11 @@ sealed class Screen {
object Compose : Screen()
}

@Model
object AppState {
var currentScreen: Screen = Screen.Home
var theme = lightThemeColors
}

fun navigateTo(destination: Screen) {
AppState.currentScreen = destination
}
class AppStateViewModel : ViewModel() {
val currentScreen = MutableLiveData<Screen>(Screen.Home)
val theme = MutableLiveData(lightThemeColors)

fun isLightTheme(): Boolean {
return AppState.theme.isLight
fun navigateTo(destination: Screen) {
currentScreen.value = destination
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.sudo.rizwan.twitterclone.ui.common

import androidx.compose.Composable
import androidx.ui.graphics.Color
import androidx.ui.material.Divider
import com.sudo.rizwan.twitterclone.state.isLightTheme
import androidx.compose.material.Divider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.viewmodel.compose.viewModel
import com.sudo.rizwan.twitterclone.lightThemeColors
import com.sudo.rizwan.twitterclone.state.AppStateViewModel

@Composable
fun CustomDivider() {
Divider(color = if (isLightTheme()) Color(0xFFEEEEEE) else Color(0xFF333333))
val appState = viewModel<AppStateViewModel>()
val theme = appState.theme.observeAsState(lightThemeColors)

Divider(color = if (theme.value!!.isLight) Color(0xFFEEEEEE) else Color(0xFF333333))
}
27 changes: 18 additions & 9 deletions app/src/main/java/com/sudo/rizwan/twitterclone/ui/common/Text.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
package com.sudo.rizwan.twitterclone.ui.common

import androidx.compose.Composable
import androidx.ui.foundation.Text
import androidx.ui.graphics.Color
import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextOverflow
import androidx.ui.unit.sp
import com.sudo.rizwan.twitterclone.state.AppState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.sudo.rizwan.twitterclone.lightThemeColors
import com.sudo.rizwan.twitterclone.state.AppStateViewModel

@Composable
fun ThemedText(text: String, style: TextStyle = TextStyle()) {
val appState = viewModel<AppStateViewModel>()
val theme = appState.theme.observeAsState(lightThemeColors)

Text(
text = text,
style = style,
color = if (AppState.theme.isLight) Color(0xFF111111) else Color(0xFFEEEEEE)
color = if (theme.value!!.isLight) Color(0xFF111111) else Color(0xFFEEEEEE)
)
}


@Composable
fun GrayText(text: String) {
val appState = viewModel<AppStateViewModel>()
val theme = appState.theme.observeAsState(lightThemeColors)

Text(
text = text,
style = TextStyle(
fontSize = 14.sp,
color = if (AppState.theme.isLight) Color(0xFF666666) else Color(0xFFDDDDDD)
color = if (theme.value!!.isLight) Color(0xFF666666) else Color(0xFFDDDDDD)
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
Expand Down
Loading