Skip to content

Commit

Permalink
Merge pull request #66 from punchdrunker/use-compose
Browse files Browse the repository at this point in the history
Use compose
  • Loading branch information
punchdrunker authored Sep 2, 2023
2 parents 872065d + fad94c1 commit a329154
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 15 deletions.
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.4)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ansi (1.5.0)
ast (2.4.2)
Expand All @@ -13,18 +13,18 @@ GEM
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (9.3.0)
danger (9.3.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (>= 0.9.0, < 3.0)
faraday-http-cache (~> 2.0)
git (~> 1.13.0)
git (~> 1.13)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 5.0)
octokit (~> 6.0)
terminal-table (>= 1, < 4)
danger-android_lint (0.0.12)
danger-plugin-api (~> 1.0)
Expand All @@ -34,13 +34,13 @@ GEM
oga (~> 2.10)
danger-plugin-api (1.0.0)
danger (> 2.0)
faraday (2.7.4)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-http-cache (2.4.1)
faraday-http-cache (2.5.0)
faraday (>= 0.8)
faraday-net_http (3.0.2)
git (1.13.2)
git (1.18.0)
addressable (~> 2.8)
rchardet (~> 1.8)
kramdown (2.4.0)
Expand All @@ -49,17 +49,17 @@ GEM
kramdown (~> 2.0)
nap (1.1.0)
no_proxy_fix (0.1.2)
octokit (5.6.1)
octokit (6.1.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
oga (2.15)
ast
ruby-ll (~> 2.1)
open4 (1.3.4)
public_suffix (5.0.1)
public_suffix (5.0.3)
rchardet (1.8.0)
rexml (3.2.5)
ruby-ll (2.1.2)
rexml (3.2.6)
ruby-ll (2.1.3)
ansi
ast
ruby2_keywords (0.0.5)
Expand Down
14 changes: 14 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ android {
buildFeatures{
dataBinding = true
viewBinding true
compose true
}

composeOptions {
kotlinCompilerExtensionVersion "1.5.3"
}

// app bundleを有効にする
Expand Down Expand Up @@ -65,6 +70,7 @@ dependencies {
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.activity:activity-ktx:1.7.2"
implementation 'androidx.browser:browser:1.6.0'
// <- Kotlinでプラグインによる自動生成処理を行うための設定(kotlinを使わない場合はannotationProcessor)

Expand All @@ -91,6 +97,14 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

// compose
implementation 'androidx.activity:activity-compose:1.7.2'
implementation "androidx.compose.material3:material3:1.1.1"
implementation "androidx.compose.animation:animation:$versions.compose"
implementation "androidx.compose.ui:ui-tooling:$versions.compose"
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1'
implementation "com.google.android.material:compose-theme-adapter:1.2.1"

// utils
implementation 'joda-time:joda-time:2.12.5'

Expand Down
44 changes: 43 additions & 1 deletion app/src/main/java/tokyo/punchdrunker/hocho/LayoutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@ package tokyo.punchdrunker.hocho
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewDynamicColors
import androidx.compose.ui.tooling.preview.PreviewFontScale
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import androidx.compose.ui.unit.dp
import androidx.databinding.DataBindingUtil
import com.google.android.material.snackbar.Snackbar
import tokyo.punchdrunker.hocho.databinding.ActivityLayoutBinding

class LayoutActivity : AppCompatActivity() {
private val binding: ActivityLayoutBinding by lazy {
DataBindingUtil.setContentView<ActivityLayoutBinding>(this, R.layout.activity_layout)
DataBindingUtil.setContentView(this, R.layout.activity_layout)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -23,6 +37,11 @@ class LayoutActivity : AppCompatActivity() {
binding.fab.setOnClickListener {
Snackbar.make(it, getString(R.string.fab_message), Snackbar.LENGTH_SHORT).show()
}
binding.greeting.setContent {
MaterialTheme {
Greeting()
}
}
}

private fun setupToolbar() {
Expand All @@ -49,3 +68,26 @@ class LayoutActivity : AppCompatActivity() {

data class User constructor(val name: String, val title: String)
}

@Composable
private fun Greeting() {
Column(modifier = Modifier.padding(24.dp)) {
Text(
text = stringResource(R.string.greeting),
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier
.padding(horizontal = dimensionResource(R.dimen.margin_small))
)
Text(text = "Wonderful tonight", style = MaterialTheme.typography.headlineSmall)
}
}

@PreviewScreenSizes
@PreviewFontScale
@PreviewLightDark
@PreviewDynamicColors
@Preview
@Composable
private fun Preview() {
Greeting()
}
2 changes: 1 addition & 1 deletion app/src/main/java/tokyo/punchdrunker/hocho/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {
setupDrawer()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.main, menu)
return true
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@
android:layout_marginTop="16dp"
android:text="@string/current_night_mode"
android:textSize="32sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/compose"
android:textSize="32sp" />

<androidx.compose.ui.platform.ComposeView
android:id="@+id/greeting"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
<dimen name="margin_small">8dp</dimen>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@
<string name="transition" tools:ignore="ExtraTranslation">Transition</string>
<string name="shared_element">shared_photo</string>
<string name="simple_storage">Simple storage</string>
<string name="compose">Compose</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="switch_dark_theme">switch dark theme</string>
<string name="current_night_mode">not night</string>
<string name="night_or_not_night">night or not night?</string>
<string name="greeting">hello!</string>
</resources>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ apply plugin: 'com.github.ben-manes.versions'
buildscript {
ext.versions = [
'glide': '4.14.0',
'kotlin': '1.9.0',
'kotlin': '1.9.10',
'retrofit': '2.9.0',
'okhttp': '4.11.0',
'leakcanary': '2.12',
'compose': '1.6.0-alpha04',
]
repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion gallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdk 33
compileSdk 34

defaultConfig {
minSdkVersion 24
Expand Down

0 comments on commit a329154

Please sign in to comment.