summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2019-04-20 19:56:15 +0200
committerJoe Robinson <joe@lc8n.com>2019-04-20 19:56:15 +0200
commit8322d7cf510b22ee20d310013ec71dd4f39442bb (patch)
tree2f2366ff083dcbe739d478f704a5d4e91b292039 /app/src
parent3075e6acb5c29434b2d7be0c6ad7747a6358f045 (diff)
Added Image Pager
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/util/ImagePagerAdapter.kt55
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt24
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/view/PagerFragment.kt28
-rw-r--r--app/src/main/res/layout/pager_fragment.xml20
-rw-r--r--app/src/main/res/layout/pager_item.xml18
-rw-r--r--app/src/main/res/menu/activity_main_drawer.xml4
-rw-r--r--app/src/main/res/navigation/nav_graph.xml12
7 files changed, 157 insertions, 4 deletions
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/ImagePagerAdapter.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/ImagePagerAdapter.kt
new file mode 100644
index 0000000..628f878
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload3/util/ImagePagerAdapter.kt
@@ -0,0 +1,55 @@
+package uk.co.blatech.blaupload3.util
+
+import android.util.Log
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.RecyclerView
+import kotlinx.android.synthetic.main.pager_item.view.*
+import uk.co.blatech.blaupload3.R
+import uk.co.blatech.blaupload3.model.File
+
+class ImagePagerAdapter(private val fileList : ArrayList<File>) : RecyclerView.Adapter<ImagePagerAdapter.ViewHolder>() {
+
+ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ var imageLoader = AppController.instance?.imageLoader
+
+ fun bind(file: File) {
+ itemView.pager_image.setImageUrl(file.url.toASCIIString(), imageLoader)
+ itemView.pager_title.text = file.filename
+ }
+ }
+
+ fun updateFileList(newFileList : ArrayList<File>) {
+ Log.i("aaaaa", "bbbbb")
+ for (file in newFileList) {
+ Log.i("file", file.toString())
+ if (file.type == "image2") {
+ fileList.add(file)
+ }
+ }
+ notifyDataSetChanged()
+
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImagePagerAdapter.ViewHolder {
+ val view = LayoutInflater.from(parent.context).inflate(R.layout.pager_item, parent,false)
+ return ViewHolder(view) }
+
+ override fun getItemCount(): Int {
+ return fileList.size
+ }
+
+ override fun getItemId(position: Int): Long {
+ return position.toLong()
+ }
+
+ override fun onBindViewHolder(holder: ImagePagerAdapter.ViewHolder, position: Int) {
+ fileList?.get(position)?.let { file ->
+ if (file.type == "image2") {
+ holder.bind(file)
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt
index 2560849..51ec786 100644
--- a/app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt
+++ b/app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt
@@ -63,6 +63,30 @@ class JSONLoader {
queue.add(jsonRequest)
}
+
+ fun loadJsonToAdapter2(context: Context?, adapter: ImagePagerAdapter) {
+ val queue = Volley.newRequestQueue(context)
+ val url = "http://wupload.of.je/?format=json"
+ var fileList = ArrayList<File>()
+ val jsonRequest = JsonArrayRequest(
+ Request.Method.GET,
+ url,
+ null,
+ Response.Listener<JSONArray> { response ->
+
+ for (i in 0 until response.length()) {
+ var jsonObj = response.getJSONObject(i)
+ var upload: File = File(filename =jsonObj.getString("filename"), type = jsonObj.getString("type"), modified = jsonObj.getLong("modified"), size = jsonObj.getLong("size"))
+ fileList.add(upload)
+
+
+ }
+ adapter.updateFileList(fileList)
+ },
+ Response.ErrorListener { Log.e("json error", "narp")})
+ queue.add(jsonRequest)
+
+ }
}
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/view/PagerFragment.kt b/app/src/main/java/uk/co/blatech/blaupload3/view/PagerFragment.kt
new file mode 100644
index 0000000..bfed17c
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload3/view/PagerFragment.kt
@@ -0,0 +1,28 @@
+package uk.co.blatech.blaupload3.view
+
+import android.os.Bundle
+import android.util.Log
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import kotlinx.android.synthetic.main.pager_fragment.*
+import uk.co.blatech.blaupload3.R
+import uk.co.blatech.blaupload3.model.File
+import uk.co.blatech.blaupload3.util.ImagePagerAdapter
+import uk.co.blatech.blaupload3.util.JSONLoader
+
+class PagerFragment : Fragment() {
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ super.onCreate(savedInstanceState)
+ return inflater.inflate(R.layout.pager_fragment, container, false)
+
+ }
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ val adapter = ImagePagerAdapter(ArrayList<File>())
+ image_pager.adapter = adapter
+ JSONLoader.loadJsonToAdapter2(activity?.applicationContext, adapter)
+ Log.i("onCreateView", "bar")
+ }
+} \ No newline at end of file
diff --git a/app/src/main/res/layout/pager_fragment.xml b/app/src/main/res/layout/pager_fragment.xml
new file mode 100644
index 0000000..756b29a
--- /dev/null
+++ b/app/src/main/res/layout/pager_fragment.xml
@@ -0,0 +1,20 @@
+<?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"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/gallery_fragment">
+ <androidx.viewpager2.widget.ViewPager2
+ android:id="@+id/image_pager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+
+ />
+
+</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/pager_item.xml b/app/src/main/res/layout/pager_item.xml
new file mode 100644
index 0000000..d948c64
--- /dev/null
+++ b/app/src/main/res/layout/pager_item.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager_item"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/pager_title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/pager_image"
+ android:textSize="20dp"/>
+ <com.android.volley.toolbox.NetworkImageView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager_image"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+</FrameLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml
index 5c09517..c2ebab8 100644
--- a/app/src/main/res/menu/activity_main_drawer.xml
+++ b/app/src/main/res/menu/activity_main_drawer.xml
@@ -13,9 +13,9 @@
android:icon="@drawable/ic_menu_gallery"
android:title="Gallery"/>
<item
- android:id="@+id/nav_settings"
+ android:id="@+id/pager_fragment"
android:icon="@drawable/ic_menu_manage"
- android:title="Settings"/>
+ android:title="Pager"/>
</group>
<item android:title="Communicate">
diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml
index 77eca0e..e449c97 100644
--- a/app/src/main/res/navigation/nav_graph.xml
+++ b/app/src/main/res/navigation/nav_graph.xml
@@ -8,7 +8,7 @@
<fragment
android:id="@+id/list_fragment"
android:name="uk.co.blatech.blaupload3.view.ListFragment"
- android:label="List Fragment"
+ android:label="Blaupload List"
tools:layout="@layout/list_fragment">
<action
android:id="@+id/action_list_fragment_to_gallery_fragment"
@@ -18,11 +18,19 @@
<fragment
android:id="@+id/gallery_fragment"
android:name="uk.co.blatech.blaupload3.view.GalleryFragment"
- android:label="Gallery Fragment"
+ android:label="Blaupload Gallery"
tools:layout="@layout/gallery_fragment">
<action
android:id="@+id/action_gallery_fragment_to_list_fragment"
app:destination="@id/gallery_fragment"
/>
</fragment>
+
+ <fragment
+ android:id="@+id/pager_fragment"
+ android:name="uk.co.blatech.blaupload3.view.PagerFragment"
+ android:label="Blaupload Pager"
+ tools:layout="@layout/pager_fragment">
+
+ </fragment>
</navigation> \ No newline at end of file