Skip to content

Commit

Permalink
file picker module completed
Browse files Browse the repository at this point in the history
  • Loading branch information
professional-lalit committed Feb 4, 2020
1 parent c9d5136 commit 8a41a93
Show file tree
Hide file tree
Showing 27 changed files with 228 additions and 153 deletions.
10 changes: 10 additions & 0 deletions .idea/sonarIssues.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//apply plugin: 'com.android.library'
apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
//apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

Expand All @@ -10,7 +10,7 @@ android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.filehandling.lib"
// applicationId "com.filehandling.lib"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activities.HomeActivity"
android:name="com.filehandling.lib.ui.main.HomeActivity"
android:theme="@style/AppTheme">

</activity>
<activity android:name=".ui.TestActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=".activities.TestActivity">
</activity>
<activity
android:name=".activities.FileChooserActivity"
android:name="com.filehandling.lib.ui.explorer.FileChooserActivity"
android:exported="true"></activity>

<provider
android:name=".GenericFileProvider"
android:authorities="com.filehandling.lib.GenericFileProvider"
android:name=".utils.GenericFileProvider"
android:authorities="com.filehandling.lib.utils.GenericFileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
32 changes: 0 additions & 32 deletions app/src/main/java/com/filehandling/lib/activities/TestActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.filehandling.lib.viewholders
package com.filehandling.lib.common

import android.view.View
import android.widget.TextView
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/com/filehandling/lib/models/LibFile.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.filehandling.lib.models

import android.net.Uri
import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable

/**
* This file is created by Lalit N. Hajare on 2/4/2020.
Expand All @@ -9,15 +12,7 @@ import android.net.Uri
data class LibFile(
val uri: Uri,
var isSelected: Boolean,
val name: String,
val name: String?,
val duration: Int,
val size: Int
) {
override fun equals(other: Any?): Boolean {
return this.uri == (other as LibFile).uri
}

override fun hashCode(): Int {
return uri.hashCode()
}
}
)
37 changes: 37 additions & 0 deletions app/src/main/java/com/filehandling/lib/ui/TestActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.filehandling.lib.ui

import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.filehandling.lib.R
import com.filehandling.lib.ui.main.HomeActivity
import com.filehandling.lib.utils.beginActivityForResult
import kotlinx.android.synthetic.main.activity_test.*

class TestActivity : AppCompatActivity() {
private val REQ_FILES = 789

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
btn_choose_files.setOnClickListener {
beginActivityForResult(HomeActivity::class.java, REQ_FILES)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
val uriList = ArrayList<Uri>()
uriList.addAll(data?.getSerializableExtra("uri-list") as ArrayList<Uri>)
var fileNames = ""
for (uri in uriList) {
var path = uri.toString()
fileNames += "Path: [$path] \n\n"
}
txt_files.text = fileNames
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.filehandling.lib.fragments
package com.filehandling.lib.ui.explorer


import android.os.Bundle
Expand All @@ -9,11 +9,8 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.filehandling.lib.FolderViewModel

import com.filehandling.lib.R
import com.filehandling.lib.activities.FileChooserActivity
import com.filehandling.lib.adapters.FileAdapter
import com.filehandling.lib.models.CustomFileModel


Expand Down Expand Up @@ -52,32 +49,33 @@ class DirectoryFragment : Fragment() {
private fun setAdapter(view: View) {
recyclerFiles = view.findViewById(R.id.recycler_files)
recyclerFiles.layoutManager = LinearLayoutManager(context)
mAdapter = FileAdapter(mFileList) { file, ops ->


when (ops.ordinal) {
Ops.ADD.ordinal -> {
var fileList = mFolderViewModel.mChosenFileList.value
if(fileList == null){
fileList = ArrayList()
mAdapter =
FileAdapter(mFileList) { file, ops ->


when (ops.ordinal) {
Ops.ADD.ordinal -> {
var fileList = mFolderViewModel.mChosenFileList.value
if (fileList == null) {
fileList = ArrayList()
}
fileList.add(file)
mFolderViewModel.mChosenFileList.postValue(fileList)
file.isSelected = true
}
Ops.REMOVE.ordinal -> {
val fileList = mFolderViewModel.mChosenFileList.value
fileList?.remove(file)
mFolderViewModel.mChosenFileList.postValue(fileList)
file.isSelected = false
}
else -> {
mFolderViewModel.mCurrentDir.postValue(file)
}
fileList.add(file)
mFolderViewModel.mChosenFileList.postValue(fileList)
file.isSelected = true
}
Ops.REMOVE.ordinal -> {
val fileList = mFolderViewModel.mChosenFileList.value
fileList?.remove(file)
mFolderViewModel.mChosenFileList.postValue(fileList)
file.isSelected = false
}
else -> {
mFolderViewModel.mCurrentDir.postValue(file)
}
}

mAdapter.notifyItemChanged(mFileList.indexOf(file))
}
mAdapter.notifyItemChanged(mFileList.indexOf(file))
}
recyclerFiles.adapter = mAdapter
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.filehandling.lib.adapters
package com.filehandling.lib.ui.explorer

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.filehandling.lib.R
import com.filehandling.lib.fragments.DirectoryFragment
import com.filehandling.lib.models.CustomFileModel
import com.filehandling.lib.viewholders.FileViewHolder
import com.filehandling.lib.viewholders.ViewHolder
import com.filehandling.lib.common.ViewHolder

/**
* This file is created by Lalit N. Hajare on 1/30/2020.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package com.filehandling.lib.activities
package com.filehandling.lib.ui.explorer

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ContentResolver
import android.content.ContentUris
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.os.Handler
import android.provider.MediaStore
import android.util.Log
import android.view.MenuItem
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.filehandling.lib.FolderViewModel
import com.filehandling.lib.R
import com.filehandling.lib.fragments.DirectoryFragment
import com.filehandling.lib.models.CustomFileModel
import java.io.File

Expand Down Expand Up @@ -112,7 +105,8 @@ class FileChooserActivity : AppCompatActivity() {
}

private fun addFragment(currentDir: CustomFileModel) {
val dirFragment = DirectoryFragment()
val dirFragment =
DirectoryFragment()
dirFragment.arguments = Bundle()
dirFragment.arguments?.putSerializable("dir", currentDir)
supportFragmentManager.beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.filehandling.lib.viewholders
package com.filehandling.lib.ui.explorer

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.filehandling.lib.R
import com.filehandling.lib.fragments.DirectoryFragment
import com.filehandling.lib.models.CustomFileModel
import com.filehandling.lib.utils.DateFormatter
import com.filehandling.lib.utils.FileIconProvider
import com.filehandling.lib.common.ViewHolder
import java.util.*

/**
Expand All @@ -34,7 +34,15 @@ class FileViewHolder(
imgTick.visibility = View.INVISIBLE
}

imgFile.setImageDrawable(FileIconProvider.getFileIcon(itemView.context, file.name))
if (file.isDirectory)
imgFile.setImageDrawable(
ContextCompat.getDrawable(
itemView.context,
R.drawable.ic_folder
)!!
)
else
imgFile.setImageDrawable(FileIconProvider.getFileIcon(itemView.context, file.name))


if (!file.name.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.filehandling.lib
package com.filehandling.lib.ui.explorer

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.filehandling.lib.models.CustomFileModel
import java.io.File

/**
* This file is created by Lalit N. Hajare on 1/30/2020.
Expand Down
Loading

0 comments on commit 8a41a93

Please sign in to comment.