Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Update sdk and migrate to kotlin and androidx #54

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 29
buildToolsVersion '29.0.1'

defaultConfig {
applicationId "com.snatik.storage.sample"
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +22,13 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':storage')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':storage')
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.core:core-ktx:1.0.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
96 changes: 0 additions & 96 deletions app/src/main/java/com/snatik/storage/app/FilesAdapter.java

This file was deleted.

77 changes: 77 additions & 0 deletions app/src/main/java/com/snatik/storage/app/FilesAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.snatik.storage.app

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView

import com.snatik.storage.Storage

import java.io.File

/**
* Created by sromku on June, 2017.
*/
class FilesAdapter(context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var mFiles: List<File>? = null
private var mListener: OnFileItemListener? = null
private val mStorage: Storage = Storage(context)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.file_line_view, parent, false)
return FileViewHolder(view)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val file = mFiles!![position]
val fileViewHolder = holder as FileViewHolder
fileViewHolder.itemView.setOnClickListener { mListener!!.onClick(file) }
fileViewHolder.itemView.setOnLongClickListener {
mListener!!.onLongClick(file)
true
}
fileViewHolder.mName.text = file.name
fileViewHolder.mIcon.setImageResource(getIcon(file))
if (file.isDirectory) {
fileViewHolder.mSize.visibility = View.VISIBLE
fileViewHolder.mSize.text = ""
} else {
fileViewHolder.mSize.visibility = View.VISIBLE
fileViewHolder.mSize.text = mStorage.getReadableSize(file)
}

}

private fun getIcon(file: File) = if (file.isDirectory)
R.drawable.ic_folder_primary_24dp
else
R.drawable.ic_file_primary_24dp

override fun getItemCount(): Int {
return if (mFiles != null) mFiles!!.size else 0
}

fun setFiles(files: List<File>?) {
mFiles = files
}

fun setListener(listener: OnFileItemListener) {
mListener = listener
}

internal class FileViewHolder(v: View) : RecyclerView.ViewHolder(v) {
var mName: TextView = v.findViewById<View>(R.id.name) as TextView
var mSize: TextView = v.findViewById<View>(R.id.size) as TextView
var mIcon: ImageView = v.findViewById<View>(R.id.icon) as ImageView
}

interface OnFileItemListener {
fun onClick(file: File)

fun onLongClick(file: File)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.snatik.storage.app

import androidx.core.content.FileProvider

/**
* Created by sromku on July, 2017.
*/
class GenericFileProvider : FileProvider()
34 changes: 0 additions & 34 deletions app/src/main/java/com/snatik/storage/app/Helper.java

This file was deleted.

35 changes: 35 additions & 0 deletions app/src/main/java/com/snatik/storage/app/Helper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.snatik.storage.app

import com.google.android.material.snackbar.Snackbar
import android.view.View

/**
* Created by sromku on June, 2017.
*/
object Helper {

fun showSnackbar(message: String, root: View) {
Snackbar.make(root, message, Snackbar.LENGTH_SHORT).show()
}

fun fileExt(url: String): String? {
var newUrl = url
if (newUrl.indexOf("?") > -1) {
newUrl = newUrl.substring(0, newUrl.indexOf("?"))
}
return if (newUrl.lastIndexOf(".") == -1) {
null
} else {
var ext = newUrl.substring(newUrl.lastIndexOf(".") + 1)
if (ext.indexOf("%") > -1) {
ext = ext.substring(0, ext.indexOf("%"))
}
if (ext.indexOf("/") > -1) {
ext = ext.substring(0, ext.indexOf("/"))
}
ext.toLowerCase()

}
}

}
Loading