diff options
Diffstat (limited to 'app/src/main/java/uk')
10 files changed, 319 insertions, 0 deletions
diff --git a/app/src/main/java/uk/co/blatech/blaupload3/model/File.kt b/app/src/main/java/uk/co/blatech/blaupload3/model/File.kt new file mode 100644 index 0000000..677b852 --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/model/File.kt @@ -0,0 +1,30 @@ +package uk.co.blatech.blaupload3.model + +import java.net.URI +import java.text.SimpleDateFormat +import java.util.* + +data class File (var filename: String, var type: String, var modified: Long, var size: Long) { + + var url = URI("http://wupload.of.je/$filename") + var thumb_url = URI("http://wupload.of.je/thumbs/$filename") + var modified_formatted = SimpleDateFormat("dd/MM/yyyy mm:HH:ss").format(Date(modified*1000)) + val units = arrayOf<String>("B", "kB", "MB", "GB", "TB") + var size_lambda = { size : Long -> + var curSize = size.toDouble() + var curUnit = units[0] + for (i in 0 until units.size-1) { + if (curSize < 1000) { + break + } + curSize /= 1000 + curUnit = units[i+1] + } + val sizeRounded = String.format("%.3g", curSize) + "$sizeRounded $curUnit" + } + + var size_formatted = size_lambda(size) + + +}
\ No newline at end of file diff --git a/app/src/main/java/uk/co/blatech/blaupload3/model/Image.kt b/app/src/main/java/uk/co/blatech/blaupload3/model/Image.kt new file mode 100644 index 0000000..1ca0bff --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/model/Image.kt @@ -0,0 +1,7 @@ +//package uk.co.blatech.blaupload3.model +// +//import android.graphics.Bitmap +// +//class Image(filename: String, image: Bitmap, type: String, modified: Long, size: Long) : File(filename, type, modified, size) { +// +//}
\ No newline at end of file diff --git a/app/src/main/java/uk/co/blatech/blaupload3/model/Video.kt b/app/src/main/java/uk/co/blatech/blaupload3/model/Video.kt new file mode 100644 index 0000000..5882114 --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/model/Video.kt @@ -0,0 +1,4 @@ +//package uk.co.blatech.blaupload3.model +// +//class Video(filename: String, type: String, modified: Long, size: Long) : File(filename, type, modified, size) { +//}
\ No newline at end of file diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/AppController.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/AppController.kt new file mode 100644 index 0000000..feb0b6d --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/util/AppController.kt @@ -0,0 +1,67 @@ +package uk.co.blatech.blaupload3.util + +import android.app.Application +import android.text.TextUtils +import com.android.volley.Request +import com.android.volley.RequestQueue +import com.android.volley.toolbox.ImageLoader +import com.android.volley.toolbox.Volley + + +class AppController : Application() { + + private var mRequestQueue: RequestQueue? = null + private var mImageLoader: ImageLoader? = null + + val requestQueue: RequestQueue + get() { + if (mRequestQueue == null) { + mRequestQueue = Volley.newRequestQueue(applicationContext) + } + + return mRequestQueue!! + } + + val imageLoader: ImageLoader + get() { + requestQueue + if (mImageLoader == null) { + mImageLoader = ImageLoader( + this.mRequestQueue, + LruBitmapCache() + ) + } + return mImageLoader!! + } + + override fun onCreate() { + super.onCreate() + instance = this + } + + fun <T> addToRequestQueue(req: Request<T>, tag: String) { + // set the default tag if tag is empty + req.tag = if (TextUtils.isEmpty(tag)) TAG else tag + requestQueue.add(req) + } + + fun <T> addToRequestQueue(req: Request<T>) { + req.tag = TAG + requestQueue.add(req) + } + + fun cancelPendingRequests(tag: Any) { + if (mRequestQueue != null) { + mRequestQueue!!.cancelAll(tag) + } + } + + companion object { + + val TAG = AppController::class.java.simpleName + + @get:Synchronized + var instance: AppController? = null + private set + } +}
\ No newline at end of file diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/Config.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/Config.kt new file mode 100644 index 0000000..2b7356b --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/util/Config.kt @@ -0,0 +1,12 @@ +//package uk.co.blatech.blaupload3.util +// +//import com.natpryce.konfig.* +//import com.natpryce.konfig.ConfigurationProperties.Companion.systemProperties +// +//class Config { +// val server_url = Key("server.url", stringType) +// +// val config = systemProperties() overriding +// EnvironmentVariables() overriding +// ConfigurationProperties.fromResource("application.properties") +//}
\ No newline at end of file diff --git a/app/src/main/java/uk/co/blatech/blaupload3/util/FileListAdapter.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/FileListAdapter.kt new file mode 100644 index 0000000..b32fe6c --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/util/FileListAdapter.kt @@ -0,0 +1,37 @@ +package uk.co.blatech.blaupload3.util + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import uk.co.blatech.blaupload3.model.File +import kotlinx.android.synthetic.main.file_list_row.view.* +import uk.co.blatech.blaupload3.R + + +class FileListAdapter(private val context: Context, private val fileList : ArrayList<File>) : BaseAdapter() { + private val infater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + var imageLoader = AppController.instance?.imageLoader + override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { + val listRow = infater.inflate(R.layout.file_list_row, parent, false) + listRow.list_filename.text = fileList[position].filename + listRow.list_modified.text = fileList[position].modified_formatted.toString() + listRow.list_size.text = fileList[position].size_formatted + listRow.list_thumbnail.setImageUrl(fileList[position].thumb_url.toASCIIString(), imageLoader) + return listRow + } + + override fun getItem(position: Int): Any { + return fileList[position] + } + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + override fun getCount(): Int { + return fileList.size + } + +}
\ 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 new file mode 100644 index 0000000..dff7043 --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/util/JSONLoader.kt @@ -0,0 +1,43 @@ +package uk.co.blatech.blaupload3.util + +import android.content.Context +import android.util.Log +import android.widget.ListView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonArrayRequest +import com.android.volley.toolbox.Volley +import org.json.JSONArray +import uk.co.blatech.blaupload3.model.File + + +class JSONLoader { + companion object { + + fun getJsonListing(context: Context?, listView: ListView) { + 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) + + + } + if (context != null) { + listView.adapter = FileListAdapter(context, 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/util/LruBitmapCache.kt b/app/src/main/java/uk/co/blatech/blaupload3/util/LruBitmapCache.kt new file mode 100644 index 0000000..7fcc62e --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/util/LruBitmapCache.kt @@ -0,0 +1,28 @@ +package uk.co.blatech.blaupload3.util + +import android.graphics.Bitmap +import android.util.LruCache +import com.android.volley.toolbox.ImageLoader + +class LruBitmapCache constructor(sizeInKB: Int = defaultLruCacheSize): + LruCache<String, Bitmap>(sizeInKB), ImageLoader.ImageCache { + override fun sizeOf(key: String, value: Bitmap): Int = value.rowBytes * value.height / 1024 + + override fun getBitmap(url: String): Bitmap? { + return get(url) + } + + override fun putBitmap(url: String, bitmap: Bitmap) { + put(url, bitmap) + } + + companion object { + val defaultLruCacheSize: Int + get() { + val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt() + val cacheSize = maxMemory / 8 + return cacheSize + } + } + +}
\ 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 new file mode 100644 index 0000000..87a3db5 --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/view/ListFragment.kt @@ -0,0 +1,21 @@ +package uk.co.blatech.blaupload3.view + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import uk.co.blatech.blaupload3.R +import uk.co.blatech.blaupload3.util.JSONLoader + +class ListFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + super.onCreate(savedInstanceState) + return inflater.inflate(R.layout.list_fragment, container, false) + + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + JSONLoader.getJsonListing(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 new file mode 100644 index 0000000..1d4b7a5 --- /dev/null +++ b/app/src/main/java/uk/co/blatech/blaupload3/view/MainActivity.kt @@ -0,0 +1,70 @@ +package uk.co.blatech.blaupload3.view + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.view.Menu +import android.view.MenuItem +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 uk.co.blatech.blaupload3.R + + +class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { + + private lateinit var navController : NavController + 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) + + } + + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + when (item.itemId) { + R.id.action_settings -> return true + else -> return super.onOptionsItemSelected(item) + } + } + + 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 -> { + + } + R.id.nav_send -> { + + } + } + +// drawer_layout.closeDrawer(GravityCompat.START) + return true + } +} |