Compare commits
4 Commits
main
...
f9570806f9
| Author | SHA1 | Date | |
|---|---|---|---|
| f9570806f9 | |||
| 3544915f89 | |||
| 82e7b9ecd8 | |||
| 21f535bd59 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,7 +15,8 @@ gen/
|
|||||||
|
|
||||||
# Local configuration file (sdk path, etc)
|
# Local configuration file (sdk path, etc)
|
||||||
local.properties
|
local.properties
|
||||||
|
mqtt.properties
|
||||||
|
|
||||||
# Windows thumbnail db
|
# Windows thumbnail db
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
import java.io.FileInputStream
|
||||||
|
import java.util.Properties
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
id("org.jetbrains.kotlin.android")
|
id("org.jetbrains.kotlin.android")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mqttProperties = Properties()
|
||||||
|
mqttProperties.load(FileInputStream(rootProject.file("mqtt.properties")))
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "de.chrissthecoder.store"
|
namespace = "de.chrissthecoder.store"
|
||||||
compileSdk = 34
|
compileSdk = 34
|
||||||
@@ -13,6 +19,11 @@ android {
|
|||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0"
|
versionName = "1.0"
|
||||||
|
|
||||||
|
buildConfigField("String", "MQTT_USERNAME", mqttProperties.getProperty("username"))
|
||||||
|
buildConfigField("String", "MQTT_PASSWORD", mqttProperties.getProperty("password"))
|
||||||
|
buildConfigField("String", "MQTT_HOST", mqttProperties.getProperty("host"))
|
||||||
|
buildConfigField("String", "MQTT_PORT", mqttProperties.getProperty("port"))
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -36,6 +47,7 @@ android {
|
|||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding = true
|
||||||
|
buildConfig = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,4 +60,5 @@ dependencies {
|
|||||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
|
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
|
||||||
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
|
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
|
||||||
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
|
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
|
||||||
|
implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5")
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application android:icon="@mipmap/ic_launcher"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:label="@string/app_name"
|
||||||
android:label="@string/app_name"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:supportsRtl="true"
|
||||||
android:supportsRtl="true"
|
android:theme="@style/Theme.Store"
|
||||||
android:theme="@style/Theme.Store"
|
tools:targetApi="31">
|
||||||
tools:targetApi="31">
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -16,10 +16,8 @@
|
|||||||
android:theme="@style/Theme.Store.NoActionBar">
|
android:theme="@style/Theme.Store.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// menu should be considered as top level destinations.
|
// menu should be considered as top level destinations.
|
||||||
appBarConfiguration = AppBarConfiguration(
|
appBarConfiguration = AppBarConfiguration(
|
||||||
setOf(
|
setOf(
|
||||||
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow
|
R.id.nav_dashboard, R.id.nav_gallery, R.id.nav_slideshow
|
||||||
), drawerLayout
|
), drawerLayout
|
||||||
)
|
)
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.chrissthecoder.store.adapter
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
|
import de.chrissthecoder.store.ui.dashboard.tabfragment.ShoppinglistFragment
|
||||||
|
import de.chrissthecoder.store.ui.dashboard.tabfragment.UnderstockFragment
|
||||||
|
|
||||||
|
class DashboardFragmentPagerAdapter(manager: FragmentManager, lifecycle: Lifecycle) : FragmentStateAdapter(manager, lifecycle) {
|
||||||
|
|
||||||
|
override fun getItemCount() : Int {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFragment(position: Int) : Fragment {
|
||||||
|
return if(position == 0) { ShoppinglistFragment() }
|
||||||
|
else { UnderstockFragment() }
|
||||||
|
}
|
||||||
|
}
|
||||||
118
app/src/main/java/de/chrissthecoder/store/mqtt/MqttHandler.kt
Normal file
118
app/src/main/java/de/chrissthecoder/store/mqtt/MqttHandler.kt
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package de.chrissthecoder.store.mqtt
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import de.chrissthecoder.store.BuildConfig
|
||||||
|
import org.eclipse.paho.client.mqttv3.*
|
||||||
|
|
||||||
|
class MqttHandler {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val LINE = "_________________________"
|
||||||
|
|
||||||
|
private const val CONNECTION_TIMEOUT = 3
|
||||||
|
private const val CONNECTION_KEEP_ALIVE_INTERVAL = 60
|
||||||
|
private const val CONNECTION_CLEAN_SESSION = true
|
||||||
|
private const val CONNECTION_RECONNECT = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private val client: MqttClient
|
||||||
|
|
||||||
|
init {
|
||||||
|
Log.d(this.javaClass.name, "Enter Initializer")
|
||||||
|
|
||||||
|
val clientId: String = "Test Smartphone"
|
||||||
|
|
||||||
|
val serverURL = "tcp://" + BuildConfig.MQTT_HOST + ":" + BuildConfig.MQTT_PORT
|
||||||
|
client = MqttClient(serverURL, clientId, null)
|
||||||
|
|
||||||
|
Log.d(this.javaClass.name, "Set Mqtt Call-Back and Connect")
|
||||||
|
|
||||||
|
client.setCallback(object : MqttCallbackExtended {
|
||||||
|
override fun connectionLost(cause: Throwable?) {
|
||||||
|
Log.w(this.javaClass.name, "Connection Lost")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun messageArrived(topic: String?, message: MqttMessage?) {
|
||||||
|
Log.d(this.javaClass.name, "Message on Topic: \"" + topic + "\" Arrived")
|
||||||
|
val payload = message?.payload?.toString(Charsets.UTF_8)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deliveryComplete(token: IMqttDeliveryToken?) {
|
||||||
|
Log.d(this.javaClass.name, "Message successful delivered")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun connectComplete(reconnect: Boolean, serverURI: String?) {
|
||||||
|
var message = "Successful "
|
||||||
|
if (reconnect) { message += "re" }
|
||||||
|
message += "connected to: "
|
||||||
|
serverURI?.let { Log.d(this.javaClass.name, message + it) }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Log.d(this.javaClass.name, "MQTT Credentials:")
|
||||||
|
Log.d(this.javaClass.name, LINE)
|
||||||
|
Log.d(this.javaClass.name, "Client ID: " + clientId)
|
||||||
|
Log.d(this.javaClass.name, "Server URL: " + serverURL)
|
||||||
|
Log.d(this.javaClass.name, "Username: " + BuildConfig.MQTT_USERNAME)
|
||||||
|
Log.d(this.javaClass.name, "Password: " + BuildConfig.MQTT_PASSWORD)
|
||||||
|
Log.d(this.javaClass.name, LINE)
|
||||||
|
|
||||||
|
connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun connect() {
|
||||||
|
try {
|
||||||
|
Log.d(this.javaClass.name, "Connecting to Broker...")
|
||||||
|
|
||||||
|
// Set up the connection options
|
||||||
|
val mqttConnectOptions = MqttConnectOptions()
|
||||||
|
mqttConnectOptions.isAutomaticReconnect = CONNECTION_RECONNECT
|
||||||
|
mqttConnectOptions.isCleanSession = CONNECTION_CLEAN_SESSION
|
||||||
|
mqttConnectOptions.userName = BuildConfig.MQTT_USERNAME
|
||||||
|
mqttConnectOptions.password = BuildConfig.MQTT_PASSWORD.toCharArray()
|
||||||
|
mqttConnectOptions.connectionTimeout = CONNECTION_TIMEOUT
|
||||||
|
mqttConnectOptions.keepAliveInterval = CONNECTION_KEEP_ALIVE_INTERVAL
|
||||||
|
|
||||||
|
client.connect(mqttConnectOptions)
|
||||||
|
} catch (ex: MqttException) {
|
||||||
|
handleConnectionFailure(ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleConnectionFailure(cause: Throwable?) {
|
||||||
|
Log.w(this.javaClass.name,"Failed to connect: ${Log.getStackTraceString(cause)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun subscribe(topic: String, qos: Int = 0) {
|
||||||
|
try {
|
||||||
|
Log.d(this.javaClass.name, "Subscribe to Topic: $topic")
|
||||||
|
client.subscribe(topic, qos)
|
||||||
|
} catch (ex: MqttException) {
|
||||||
|
Log.e(this.javaClass.name,"Error on subscribing to Topic: $topic", ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun publish(topic: String, msg: String, qos: Int = 0, retained: Boolean = false) {
|
||||||
|
try {
|
||||||
|
val mqttMessage = MqttMessage(msg.toByteArray())
|
||||||
|
client.publish(topic, mqttMessage.payload, qos, retained)
|
||||||
|
Log.d(this.javaClass.name, "Message published to topic `$topic`: $msg")
|
||||||
|
} catch (e: MqttException) {
|
||||||
|
Log.e(this.javaClass.name, "Error publishing to $topic: " + e.message, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disconnect() {
|
||||||
|
try {
|
||||||
|
Log.d(this.javaClass.name, "Disconnecting from Broker...")
|
||||||
|
client.disconnect()
|
||||||
|
} catch (e: MqttException) {
|
||||||
|
Log.e(this.javaClass.name, "Error disconnection from Broker: " + e.message, e)
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isConnected(): Boolean {
|
||||||
|
return client.isConnected
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package de.chrissthecoder.store.ui.dashboard
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||||
|
import com.google.android.material.tabs.TabLayout
|
||||||
|
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
|
||||||
|
import de.chrissthecoder.store.adapter.DashboardFragmentPagerAdapter
|
||||||
|
import de.chrissthecoder.store.databinding.FragmentDashboardBinding
|
||||||
|
|
||||||
|
class DashboardFragment : Fragment() {
|
||||||
|
|
||||||
|
private var _binding: FragmentDashboardBinding? = null
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
|
private lateinit var tabLayout: TabLayout
|
||||||
|
private lateinit var viewPager: ViewPager2
|
||||||
|
private lateinit var adapter: DashboardFragmentPagerAdapter
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) : View {
|
||||||
|
_binding = FragmentDashboardBinding.inflate(inflater, container, false)
|
||||||
|
val root: View = binding.root
|
||||||
|
|
||||||
|
val dashboardViewModel = ViewModelProvider(this).get(DashboardViewModel::class.java)
|
||||||
|
|
||||||
|
tabLayout = binding.tabLayout
|
||||||
|
viewPager = binding.viewPager
|
||||||
|
adapter = DashboardFragmentPagerAdapter(parentFragmentManager, lifecycle)
|
||||||
|
viewPager.adapter = adapter
|
||||||
|
|
||||||
|
tabLayout.addOnTabSelectedListener(object : OnTabSelectedListener {
|
||||||
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||||
|
if (tab != null) {
|
||||||
|
viewPager.currentItem = tab.position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab?) { }
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab?) { }
|
||||||
|
})
|
||||||
|
|
||||||
|
viewPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
super.onPageSelected(position)
|
||||||
|
tabLayout.selectTab(tabLayout.getTabAt(position))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package de.chrissthecoder.store.ui.home
|
package de.chrissthecoder.store.ui.dashboard
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
class HomeViewModel : ViewModel() {
|
class DashboardViewModel : ViewModel() {
|
||||||
|
|
||||||
private val _text = MutableLiveData<String>().apply {
|
private val _text = MutableLiveData<String>().apply {
|
||||||
value = "This is home Fragment"
|
value = "This is home Fragment"
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package de.chrissthecoder.store.ui.dashboard.tabfragment
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import de.chrissthecoder.store.R
|
||||||
|
|
||||||
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
|
private const val ARG_PARAM1 = "param1"
|
||||||
|
private const val ARG_PARAM2 = "param2"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple [Fragment] subclass.
|
||||||
|
* Use the [ShoppinglistFragment.newInstance] factory method to
|
||||||
|
* create an instance of this fragment.
|
||||||
|
*/
|
||||||
|
class ShoppinglistFragment : Fragment() {
|
||||||
|
// TODO: Rename and change types of parameters
|
||||||
|
private var param1: String? = null
|
||||||
|
private var param2: String? = null
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
arguments?.let {
|
||||||
|
param1 = it.getString(ARG_PARAM1)
|
||||||
|
param2 = it.getString(ARG_PARAM2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_shoppinglist, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Use this factory method to create a new instance of
|
||||||
|
* this fragment using the provided parameters.
|
||||||
|
*
|
||||||
|
* @param param1 Parameter 1.
|
||||||
|
* @param param2 Parameter 2.
|
||||||
|
* @return A new instance of fragment ShoppinglistFragment.
|
||||||
|
*/
|
||||||
|
// TODO: Rename and change types and number of parameters
|
||||||
|
@JvmStatic
|
||||||
|
fun newInstance(param1: String, param2: String) =
|
||||||
|
ShoppinglistFragment().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
putString(ARG_PARAM1, param1)
|
||||||
|
putString(ARG_PARAM2, param2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package de.chrissthecoder.store.ui.dashboard.tabfragment
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import de.chrissthecoder.store.R
|
||||||
|
|
||||||
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
|
private const val ARG_PARAM1 = "param1"
|
||||||
|
private const val ARG_PARAM2 = "param2"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple [Fragment] subclass.
|
||||||
|
* Use the [UnderstockFragment.newInstance] factory method to
|
||||||
|
* create an instance of this fragment.
|
||||||
|
*/
|
||||||
|
class UnderstockFragment : Fragment() {
|
||||||
|
// TODO: Rename and change types of parameters
|
||||||
|
private var param1: String? = null
|
||||||
|
private var param2: String? = null
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
arguments?.let {
|
||||||
|
param1 = it.getString(ARG_PARAM1)
|
||||||
|
param2 = it.getString(ARG_PARAM2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_understock, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Use this factory method to create a new instance of
|
||||||
|
* this fragment using the provided parameters.
|
||||||
|
*
|
||||||
|
* @param param1 Parameter 1.
|
||||||
|
* @param param2 Parameter 2.
|
||||||
|
* @return A new instance of fragment UnderstockFragment.
|
||||||
|
*/
|
||||||
|
// TODO: Rename and change types and number of parameters
|
||||||
|
@JvmStatic
|
||||||
|
fun newInstance(param1: String, param2: String) =
|
||||||
|
UnderstockFragment().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
putString(ARG_PARAM1, param1)
|
||||||
|
putString(ARG_PARAM2, param2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package de.chrissthecoder.store.ui.home
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import de.chrissthecoder.store.databinding.FragmentHomeBinding
|
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
|
||||||
|
|
||||||
private var _binding: FragmentHomeBinding? = null
|
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
|
||||||
// onDestroyView.
|
|
||||||
private val binding get() = _binding!!
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater,
|
|
||||||
container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View {
|
|
||||||
val homeViewModel =
|
|
||||||
ViewModelProvider(this).get(HomeViewModel::class.java)
|
|
||||||
|
|
||||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
|
||||||
val root: View = binding.root
|
|
||||||
|
|
||||||
val textView: TextView = binding.textHome
|
|
||||||
homeViewModel.text.observe(viewLifecycleOwner) {
|
|
||||||
textView.text = it
|
|
||||||
}
|
|
||||||
return root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
super.onDestroyView()
|
|
||||||
_binding = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
39
app/src/main/res/layout/fragment_dashboard.xml
Normal file
39
app/src/main/res/layout/fragment_dashboard.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.dashboard.DashboardFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/tabLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0">
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/tab_shoppinglist" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/tab_understock" />
|
||||||
|
|
||||||
|
</com.google.android.material.tabs.TabLayout>
|
||||||
|
|
||||||
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
|
android:id="@+id/viewPager"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -4,19 +4,16 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.home.HomeFragment">
|
tools:context=".ui.dashboard.tabfragment.ShoppinglistFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_home"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:text="Einkaufszettel"
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="20sp"
|
android:textSize="32sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintVertical_bias="0.5" />
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
19
app/src/main/res/layout/fragment_understock.xml
Normal file
19
app/src/main/res/layout/fragment_understock.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.dashboard.tabfragment.UnderstockFragment">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Minderbestand"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textSize="32sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.5" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_home"
|
android:id="@+id/nav_dashboard"
|
||||||
android:icon="@drawable/ic_menu_camera"
|
android:icon="@drawable/ic_menu_camera"
|
||||||
android:title="@string/menu_home" />
|
android:title="@string/menu_dashboard" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_gallery"
|
android:id="@+id/nav_gallery"
|
||||||
android:icon="@drawable/ic_menu_gallery"
|
android:icon="@drawable/ic_menu_gallery"
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/mobile_navigation"
|
android:id="@+id/mobile_navigation"
|
||||||
app:startDestination="@+id/nav_home">
|
app:startDestination="@+id/nav_dashboard">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_home"
|
android:id="@+id/nav_dashboard"
|
||||||
android:name="de.chrissthecoder.store.ui.home.HomeFragment"
|
android:name="de.chrissthecoder.store.ui.dashboard.DashboardFragment"
|
||||||
android:label="@string/menu_home"
|
android:label="@string/menu_dashboard"
|
||||||
tools:layout="@layout/fragment_home" />
|
tools:layout="@layout/fragment_dashboard" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_gallery"
|
android:id="@+id/nav_gallery"
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
<string name="nav_header_desc">Navigation header</string>
|
<string name="nav_header_desc">Navigation header</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
<string name="menu_home">Home</string>
|
<string name="menu_dashboard">Dashboard</string>
|
||||||
<string name="menu_gallery">Gallery</string>
|
<string name="menu_gallery">Gallery</string>
|
||||||
<string name="menu_slideshow">Slideshow</string>
|
<string name="menu_slideshow">Slideshow</string>
|
||||||
|
|
||||||
|
<string name="tab_shoppinglist">Einkaufszettel</string>
|
||||||
|
<string name="tab_understock">Minderbestand</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application") version "8.2.2" apply false
|
id("com.android.application") version "8.3.0" apply false
|
||||||
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
|
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
|
||||||
}
|
}
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Thu Mar 07 13:51:32 CET 2024
|
#Thu Mar 07 13:51:32 CET 2024
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
Reference in New Issue
Block a user