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 8a41a93 commit 73f6737
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .idea/sonarIssues.xml

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

61 changes: 55 additions & 6 deletions app/src/main/java/com/filehandling/lib/ui/main/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.filehandling.lib.ui.main

import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import com.google.android.material.tabs.TabLayout
import androidx.viewpager.widget.ViewPager
Expand All @@ -19,7 +21,9 @@ import com.filehandling.lib.utils.beginActivityForResult

class HomeActivity : AppCompatActivity() {

private val REQ_FILE_ACCESS = 23
private val REQ_FILE_EXPLORER = 78

lateinit var mPageViewModel: PageViewModel

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -30,12 +34,7 @@ class HomeActivity : AppCompatActivity() {
.create(PageViewModel::class.java)

initActionBar()
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.view_pager)
viewPager.adapter = sectionsPagerAdapter
val tabs: TabLayout = findViewById(R.id.tabs)
tabs.setupWithViewPager(viewPager)

getPerms()
}

private fun initActionBar() {
Expand All @@ -48,6 +47,56 @@ class HomeActivity : AppCompatActivity() {
}
}


private fun getPerms() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(
arrayOf(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
, android.Manifest.permission.READ_EXTERNAL_STORAGE
), REQ_FILE_ACCESS
)
} else {
initSections()
}
} else {
initSections()
}
}

private fun initSections() {
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.view_pager)
viewPager.adapter = sectionsPagerAdapter
val tabs: TabLayout = findViewById(R.id.tabs)
tabs.setupWithViewPager(viewPager)
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (permissions.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED
) {
initSections()
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(
arrayOf(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
, android.Manifest.permission.READ_EXTERNAL_STORAGE
), REQ_FILE_ACCESS
)
}
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_home, menu)
return super.onCreateOptionsMenu(menu)
Expand Down

0 comments on commit 73f6737

Please sign in to comment.