From 8cfe6e97fa332912094f0f39970b14957f9b3672 Mon Sep 17 00:00:00 2001 From: peet Date: Tue, 4 Jan 2022 02:34:29 +0100 Subject: [PATCH] more graphql queries --- app/src/main/AndroidManifest.xml | 3 ++- .../graphql/org/ddnss/sfs/getUsers.graphql | 10 +++++++++ .../java/org/dnss/sfs/git/wdg/noise/Apollo.kt | 10 +++++++++ .../dnss/sfs/git/wdg/noise/MainActivity.kt | 20 ------------------ .../wdg/noise/ui/gallery/GalleryFragment.kt | 21 ++++++++++++------- app/src/main/res/layout/content_main.xml | 16 -------------- app/src/main/res/layout/fragment_gallery.xml | 18 ++++++---------- 7 files changed, 42 insertions(+), 56 deletions(-) create mode 100644 app/src/main/graphql/org/ddnss/sfs/getUsers.graphql create mode 100644 app/src/main/java/org/dnss/sfs/git/wdg/noise/Apollo.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6071d07..18ee802 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,8 @@ + android:theme="@style/Theme.Noise.NoActionBar" + android:exported="true"> diff --git a/app/src/main/graphql/org/ddnss/sfs/getUsers.graphql b/app/src/main/graphql/org/ddnss/sfs/getUsers.graphql new file mode 100644 index 0000000..76c7afc --- /dev/null +++ b/app/src/main/graphql/org/ddnss/sfs/getUsers.graphql @@ -0,0 +1,10 @@ +query getUsers { + users { + id + userName + displayName + activated + created + lastOnline + } +} \ No newline at end of file diff --git a/app/src/main/java/org/dnss/sfs/git/wdg/noise/Apollo.kt b/app/src/main/java/org/dnss/sfs/git/wdg/noise/Apollo.kt new file mode 100644 index 0000000..f141335 --- /dev/null +++ b/app/src/main/java/org/dnss/sfs/git/wdg/noise/Apollo.kt @@ -0,0 +1,10 @@ +package org.dnss.sfs.git.wdg.noise +import com.apollographql.apollo3.ApolloClient + +class Apollo { + + val apolloClient = ApolloClient.Builder() + .serverUrl("https://noise.sfs.ddnss.org/graphql") + .build() + +} \ No newline at end of file diff --git a/app/src/main/java/org/dnss/sfs/git/wdg/noise/MainActivity.kt b/app/src/main/java/org/dnss/sfs/git/wdg/noise/MainActivity.kt index 2fb3485..f2cd98f 100644 --- a/app/src/main/java/org/dnss/sfs/git/wdg/noise/MainActivity.kt +++ b/app/src/main/java/org/dnss/sfs/git/wdg/noise/MainActivity.kt @@ -45,11 +45,6 @@ class MainActivity : AppCompatActivity() { ) setupActionBarWithNavController(navController, appBarConfiguration) navView.setupWithNavController(navController) - - addButton( "a", 0xff0000) - addButton( "b", 0xff0000) - addButton( "c", 0xff0000) - addButton( "d", 0xff0000) } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -63,19 +58,4 @@ class MainActivity : AppCompatActivity() { return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() } - fun addButton(userName: String, color: Int) { - val contactScrollField = findViewById(R.id.linear_layout) - // = findViewById(R.id.linear_layout) as LinearLayout - - val dynamicButton = Button(this) - /*dynamicButton.layoutParams = LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT - )*/ - dynamicButton.text = userName - dynamicButton.setBackgroundColor(Color.GREEN) - - contactScrollField.addView(dynamicButton) - } - } \ No newline at end of file diff --git a/app/src/main/java/org/dnss/sfs/git/wdg/noise/ui/gallery/GalleryFragment.kt b/app/src/main/java/org/dnss/sfs/git/wdg/noise/ui/gallery/GalleryFragment.kt index f3be78f..6655e62 100644 --- a/app/src/main/java/org/dnss/sfs/git/wdg/noise/ui/gallery/GalleryFragment.kt +++ b/app/src/main/java/org/dnss/sfs/git/wdg/noise/ui/gallery/GalleryFragment.kt @@ -1,14 +1,14 @@ package org.dnss.sfs.git.wdg.noise.ui.gallery import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.TextView import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider -import org.dnss.sfs.git.wdg.noise.R +import androidx.lifecycle.lifecycleScope +import org.dnss.sfs.git.wdg.noise.Apollo import org.dnss.sfs.git.wdg.noise.databinding.FragmentGalleryBinding class GalleryFragment : Fragment() { @@ -31,13 +31,20 @@ class GalleryFragment : Fragment() { _binding = FragmentGalleryBinding.inflate(inflater, container, false) val root: View = binding.root - val textView: TextView = binding.textGallery - galleryViewModel.text.observe(viewLifecycleOwner, Observer { - textView.text = it - }) return root } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + lifecycleScope.launchWhenResumed { + val response = Apollo.apolloClient.query(getUsers()).execute() + + Log.d("getUsers", "Data:: ${response.data}") + } + } + + override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 63c598a..6e0ea39 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -17,20 +17,4 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:navGraph="@navigation/mobile_navigation" /> - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_gallery.xml b/app/src/main/res/layout/fragment_gallery.xml index 643fe25..4e39916 100644 --- a/app/src/main/res/layout/fragment_gallery.xml +++ b/app/src/main/res/layout/fragment_gallery.xml @@ -7,16 +7,10 @@ tools:context=".ui.gallery.GalleryFragment"> - \ No newline at end of file + android:text="TestData" + tools:layout_editor_absoluteX="99dp" + tools:layout_editor_absoluteY="185dp" /> +