From b14ad1dc435ff86a7438d2b2b6c75e25dad7b114 Mon Sep 17 00:00:00 2001 From: Paul-Louis NECH Date: Sun, 4 Mar 2018 16:31:04 +0100 Subject: [PATCH] feat(UI): HomeActivity with logs --- app/src/main/AndroidManifest.xml | 2 +- app/src/main/java/fr/plnech/lifelogger/HomeActivity.kt | 39 --------------------------------------- app/src/main/java/fr/plnech/lifelogger/ui/HomeActivity.kt | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/activity_home.xml | 4 ++-- app/src/main/res/layout/content_home.xml | 19 +++++++++++-------- app/src/main/res/menu/menu_home.xml | 2 +- 6 files changed, 95 insertions(+), 51 deletions(-) delete mode 100644 app/src/main/java/fr/plnech/lifelogger/HomeActivity.kt create mode 100644 app/src/main/java/fr/plnech/lifelogger/ui/HomeActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 912e668..ec38812 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> diff --git a/app/src/main/java/fr/plnech/lifelogger/HomeActivity.kt b/app/src/main/java/fr/plnech/lifelogger/HomeActivity.kt deleted file mode 100644 index 4c0de40..0000000 --- a/app/src/main/java/fr/plnech/lifelogger/HomeActivity.kt +++ /dev/null @@ -1,39 +0,0 @@ -package fr.plnech.lifelogger - -import android.os.Bundle -import android.support.design.widget.Snackbar -import android.support.v7.app.AppCompatActivity -import android.view.Menu -import android.view.MenuItem - -import kotlinx.android.synthetic.main.activity_home.* - -class HomeActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_home) - setSupportActionBar(toolbar) - - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - } - } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_home, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return when (item.itemId) { - R.id.action_settings -> true - else -> super.onOptionsItemSelected(item) - } - } -} diff --git a/app/src/main/java/fr/plnech/lifelogger/ui/HomeActivity.kt b/app/src/main/java/fr/plnech/lifelogger/ui/HomeActivity.kt new file mode 100644 index 0000000..3e42709 --- /dev/null +++ b/app/src/main/java/fr/plnech/lifelogger/ui/HomeActivity.kt @@ -0,0 +1,80 @@ +package fr.plnech.lifelogger.ui + +import android.os.Bundle +import android.support.design.widget.Snackbar +import android.support.v7.app.AppCompatActivity +import android.view.Menu +import android.view.MenuItem +import fr.plnech.lifelogger.R +import fr.plnech.lifelogger.model.DataPoint +import fr.plnech.lifelogger.model.Log +import fr.plnech.lifelogger.model.LogAdapter +import kotlinx.android.synthetic.main.activity_home.* +import kotlinx.android.synthetic.main.content_home.* + +class HomeActivity : AppCompatActivity() { + + + private lateinit var adapter: LogAdapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_home) + setSupportActionBar(toolbar) + + fab.setOnClickListener { view -> + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() + } + + adapter = LogAdapter(this, generateDebugData()) + list?.adapter = adapter + adapter.notifyDataSetChanged() + +// val model = ViewModelProviders.of(this).get(LogViewModel::class.java) +// model.logs.observe(this, Observer { +// +// }) + + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.menu_home, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + return when (item.itemId) { + R.id.action_settings -> true + else -> super.onOptionsItemSelected(item) + } + } + + private fun generateDebugData(): ArrayList { + var logs : ArrayList = ArrayList() + val stairs = Log("Stairway to heaven") + stairs.addPoint(DataPoint("stairs", 7)) + stairs.addPoint(DataPoint("lift")) + stairs.addPoint(DataPoint("stairs", 4)) + stairs.addPoint(DataPoint("stairs", 4)) + stairs.addPoint(DataPoint("lift")) + + val moods = Log("MoodBoard") + moods.addPoint(DataPoint("happy")) + moods.addPoint(DataPoint("focused")) + moods.addPoint(DataPoint("relax")) + + val mind = Log("MindBoard") + mind.addPoint(DataPoint("HeadSpace", 10)) + mind.addPoint(DataPoint("HeadSpace", 5)) + + logs.add(stairs) + logs.add(moods) + logs.add(mind) + return logs + } +} diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 98ea454..6fae260 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="fr.plnech.lifelogger.HomeActivity"> + tools:context="fr.plnech.lifelogger.ui.HomeActivity"> + app:srcCompat="@android:drawable/ic_dialog_dialer"/> diff --git a/app/src/main/res/layout/content_home.xml b/app/src/main/res/layout/content_home.xml index d22f8a2..adf3323 100644 --- a/app/src/main/res/layout/content_home.xml +++ b/app/src/main/res/layout/content_home.xml @@ -6,16 +6,19 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" - tools:context="fr.plnech.lifelogger.HomeActivity" + tools:context="fr.plnech.lifelogger.ui.HomeActivity" tools:showIn="@layout/activity_home"> - - diff --git a/app/src/main/res/menu/menu_home.xml b/app/src/main/res/menu/menu_home.xml index 3322162..0d1cc05 100644 --- a/app/src/main/res/menu/menu_home.xml +++ b/app/src/main/res/menu/menu_home.xml @@ -1,7 +1,7 @@ + tools:context="fr.plnech.lifelogger.ui.HomeActivity">