diff options
author | Joe Robinson <joe@lc8n.com> | 2019-04-20 17:45:19 +0200 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2019-04-20 17:45:19 +0200 |
commit | 3075e6acb5c29434b2d7be0c6ad7747a6358f045 (patch) | |
tree | 214d37dfb9c7d2f4aa0dc07cb109f66e4165cf74 /app/src/main/java/uk/co/blatech | |
parent | 9d430209d39d0e68f6311adfff9d476c8856f662 (diff) |
Added Gallery View
Diffstat (limited to 'app/src/main/java/uk/co/blatech')
5 files changed, 139 insertions, 29 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 } + } |