summaryrefslogtreecommitdiff
path: root/app/src/main/java/uk/co/blatech
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/uk/co/blatech')
-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
3 files changed, 107 insertions, 0 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