summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/util/ImageGalleryAdapter.kt57
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt32
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/view/GalleryFragment.kt33
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt2
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt44
-rw-r--r--app/src/main/res/layout/activity_main.xml34
-rw-r--r--app/src/main/res/layout/gallery_fragment.xml14
-rw-r--r--app/src/main/res/layout/image_gallery_item.xml16
-rw-r--r--app/src/main/res/menu/activity_main_drawer.xml4
-rw-r--r--app/src/main/res/navigation/nav_graph.xml26
10 files changed, 213 insertions, 49 deletions
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/ImageGalleryAdapter.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/ImageGalleryAdapter.kt
new file mode 100644
index 0000000..82ce858
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload3/util/ImageGalleryAdapter.kt
@@ -0,0 +1,57 @@
+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.image_gallery_item.view.*
+import uk.co.blatech.blaupload3.R
+import uk.co.blatech.blaupload3.model.File
+
+class ImageGalleryAdapter(private val fileList : ArrayList<File>) : RecyclerView.Adapter<ImageGalleryAdapter.ViewHolder>(){
+
+
+ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ var imageLoader = AppController.instance?.imageLoader
+
+ fun bind(file: File) {
+ itemView.gallery_thumbnail.setImageUrl(file.thumb_url.toASCIIString(), imageLoader)
+ itemView.gallery_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 getItemId(position: Int): Long {
+ return position.toLong()
+ }
+
+ override fun getItemCount(): Int {
+ return fileList.size
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
+ val view = LayoutInflater.from(parent.context).inflate(R.layout.image_gallery_item, parent,false)
+ return ViewHolder(view)
+ }
+
+ override fun onBindViewHolder(holder: 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 dff7043..2560849 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
@@ -14,7 +14,7 @@ import uk.co.blatech.blaupload3.model.File
class JSONLoader {
companion object {
- fun getJsonListing(context: Context?, listView: ListView) {
+ fun loadJsonToList(context: Context?, listView: ListView) {
val queue = Volley.newRequestQueue(context)
val url = "http://wupload.of.je/?format=json"
var fileList = ArrayList<File>()
@@ -39,5 +39,33 @@ class JSONLoader {
queue.add(jsonRequest)
}
+
+ fun loadJsonToAdapter(context: Context?, adapter: ImageGalleryAdapter) {
+ 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)
+
+ }
}
-} \ No newline at end of file
+
+
+
+
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/view/GalleryFragment.kt b/app/src/main/java/uk/co/blatech/blaupload3/view/GalleryFragment.kt
new file mode 100644
index 0000000..bcee796
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload3/view/GalleryFragment.kt
@@ -0,0 +1,33 @@
+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 androidx.recyclerview.widget.GridLayoutManager
+import kotlinx.android.synthetic.main.gallery_fragment.*
+import uk.co.blatech.blaupload3.R
+import uk.co.blatech.blaupload3.model.File
+import uk.co.blatech.blaupload3.util.ImageGalleryAdapter
+import uk.co.blatech.blaupload3.util.JSONLoader
+
+class GalleryFragment : Fragment() {
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ super.onCreate(savedInstanceState)
+ Log.i("onCreateView", "foo")
+
+ return inflater.inflate(R.layout.gallery_fragment, container, false)
+
+ }
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ val layoutManager = GridLayoutManager(activity?.applicationContext, 5)
+ gallery_view.layoutManager = layoutManager
+ val adapter =ImageGalleryAdapter(ArrayList<File>())
+ gallery_view.adapter = adapter
+ JSONLoader.loadJsonToAdapter(activity?.applicationContext, adapter)
+ Log.i("onCreateView", "bar")
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt b/app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt
index 87a3db5..b326f46 100644
--- a/app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt
+++ b/app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt
@@ -16,6 +16,6 @@ class ListFragment : Fragment() {
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- JSONLoader.getJsonListing(activity?.applicationContext, activity?.findViewById(R.id.file_list)!!)
+ JSONLoader.loadJsonToList(activity?.applicationContext, activity?.findViewById(R.id.file_list)!!)
}
} \ No newline at end of file
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt b/app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt
index 1d4b7a5..c2f27a5 100644
--- a/app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt
+++ b/app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt
@@ -4,24 +4,28 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
+import androidx.core.view.GravityCompat
import androidx.navigation.NavController
import kotlinx.android.synthetic.main.activity_main.*
import androidx.navigation.Navigation
-import androidx.navigation.ui.NavigationUI
-import com.google.android.material.navigation.NavigationView
+import androidx.navigation.ui.*
import uk.co.blatech.blaupload3.R
-class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
+class MainActivity : AppCompatActivity(){
private lateinit var navController : NavController
+ private lateinit var appBarConfiguration : AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
+
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
NavigationUI.setupWithNavController(nav_view, navController)
- nav_view.setNavigationItemSelectedListener(this)
-
+ appBarConfiguration = AppBarConfiguration(navController.graph, drawer_layout)
+ setSupportActionBar(toolbar)
+ setupActionBarWithNavController(navController, appBarConfiguration)
+ nav_view.setupWithNavController(navController)
}
@@ -42,29 +46,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
- override fun onNavigationItemSelected(item: MenuItem): Boolean {
- // Handle navigation view item clicks here.
- when (item.itemId) {
- R.id.nav_upload -> {
-
- // Handle the camera action
- }
- R.id.nav_gallery -> {
- navController.navigate(R.id.file_list)
-// }
- }
- R.id.nav_settings -> {
-
- }
- R.id.nav_share -> {
+ override fun onSupportNavigateUp(): Boolean {
+ return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
+ }
- }
- R.id.nav_send -> {
- }
+ override fun onBackPressed() {
+ if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
+ drawer_layout.closeDrawer(GravityCompat.START)
+ } else {
+ super.onBackPressed()
}
-
-// drawer_layout.closeDrawer(GravityCompat.START)
- return true
}
+
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4cc95a2..3e1b702 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -9,18 +9,32 @@
android:fitsSystemWindows="true"
tools:openDrawer="start">
- <!--<include-->
- <!--layout="@layout/app_bar_main"-->
- <!--android:layout_width="match_parent"-->
- <!--android:layout_height="match_parent"/>-->
- <fragment
- android:name="androidx.navigation.fragment.NavHostFragment"
- android:id="@+id/nav_host_fragment"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- app:defaultNavHost="true"
- app:navGraph="@navigation/nav_graph"
- />
+ android:orientation="vertical">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"/>
+
+ </com.google.android.material.appbar.AppBarLayout>
+ <fragment
+ android:name="androidx.navigation.fragment.NavHostFragment"
+ android:id="@+id/nav_host_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:defaultNavHost="true"
+ app:navGraph="@navigation/nav_graph"
+ />
+
+ </LinearLayout>
<com.google.android.material.navigation.NavigationView
diff --git a/app/src/main/res/layout/gallery_fragment.xml b/app/src/main/res/layout/gallery_fragment.xml
new file mode 100644
index 0000000..b05559c
--- /dev/null
+++ b/app/src/main/res/layout/gallery_fragment.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/gallery_fragment">
+ <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/gallery_view"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:listitem="@layout/image_gallery_item"/>
+</RelativeLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/image_gallery_item.xml b/app/src/main/res/layout/image_gallery_item.xml
new file mode 100644
index 0000000..bd2fc7a
--- /dev/null
+++ b/app/src/main/res/layout/image_gallery_item.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+<com.android.volley.toolbox.NetworkImageView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/gallery_thumbnail"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+ <TextView
+ android:id="@+id/gallery_title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/gallery_thumbnail"
+ android:textSize="10dp"/>
+</RelativeLayout> \ 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 cab4f73..5c09517 100644
--- a/app/src/main/res/menu/activity_main_drawer.xml
+++ b/app/src/main/res/menu/activity_main_drawer.xml
@@ -5,11 +5,11 @@
<group android:checkableBehavior="single">
<item
- android:id="@+id/nav_upload"
+ android:id="@+id/list_fragment"
android:icon="@drawable/ic_menu_camera"
android:title="Upload"/>
<item
- android:id="@+id/nav_gallery"
+ android:id="@+id/gallery_fragment"
android:icon="@drawable/ic_menu_gallery"
android:title="Gallery"/>
<item
diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml
index ef2595c..77eca0e 100644
--- a/app/src/main/res/navigation/nav_graph.xml
+++ b/app/src/main/res/navigation/nav_graph.xml
@@ -3,16 +3,26 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
- app:startDestination="@id/main_fragment">
+ app:startDestination="@id/list_fragment">
>
<fragment
- android:id="@+id/main_fragment"
- android:name="uk.co.blatech.blaupload3.view.ListFragment"
- android:label="First Fragment"
- tools:layout="@layout/list_fragment" />
- <fragment
android:id="@+id/list_fragment"
android:name="uk.co.blatech.blaupload3.view.ListFragment"
- android:label="First Fragment"
- tools:layout="@layout/list_fragment" />
+ android:label="List Fragment"
+ tools:layout="@layout/list_fragment">
+ <action
+ android:id="@+id/action_list_fragment_to_gallery_fragment"
+ app:destination="@id/gallery_fragment"
+ />
+ </fragment>
+ <fragment
+ android:id="@+id/gallery_fragment"
+ android:name="uk.co.blatech.blaupload3.view.GalleryFragment"
+ android:label="Gallery Fragment"
+ tools:layout="@layout/gallery_fragment">
+ <action
+ android:id="@+id/action_gallery_fragment_to_list_fragment"
+ app:destination="@id/gallery_fragment"
+ />
+ </fragment>
</navigation> \ No newline at end of file