Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
v1.4.0s
Browse files Browse the repository at this point in the history
\+ added FileChooser style. You can now set a custom theme
\+ overrideGetView added to adapter (accessed from AdapterSetter)
\* calling build() no longer obligatory (show() can now be called directly)
\+ now possible to pass Drawables as well as drawable resouces
\+ now dialog shows after granting read permission
\* many small improvements and bug fixes
  • Loading branch information
Guiorgy authored Apr 3, 2019
1 parent 4160edc commit b51f0bb
Show file tree
Hide file tree
Showing 47 changed files with 2,067 additions and 805 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ app/src/main/java/com/obsez/android/lib/smbfilechooser/demo/App.java___jb_tmp___
library/src/main/java/com/obsez/android/lib/smbfilechooser/SmbFileChooserDialog.java___jb_tmp___
app/src/main/java/com/obsez/android/lib/smbfilechooser/demo/ChooseFileActivityFragment.java___jb_tmp___
*.iml___jb_tmp___
library/src/main/java/com/obsez/android/lib/smbfilechooser/tool/MyAdapter.java___jb_tmp___
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.4.0s - 2019-03-25

\+ added FileChooser style. You can now set a custom theme
\+ overrideGetView added to adapter (accessed from AdapterSetter)
\* calling build() no longer obligatory
\+ now possible to pass Drawables instead of drawable resouces
\+ now dialog shows after granting read permission
\* many small improvements and bug fixes

## 1.3.4s - 2019-03-12

\+ enabled R8 shrinker
Expand Down
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ configurations.all {
```

1.2.0 used jcifs 1.3.17, which only supports SMB1.\
1.3.0 an open source, maintained jcifs-ng 2.1.1 which is a breaking change! This one fully supports SMB2, and partially SMB3.
Also, target sdk was bomped to 1.8:
1.3.0 however switched to an open source, maintained [jcifs-ng](https://github.com/AgNO3/jcifs-ng) which is a breaking change! This one fully supports SMB2, and partially SMB3.
Also, target sdk was bumped to 1.8:
```java
android {
compileOptions {
Expand Down Expand Up @@ -75,7 +75,6 @@ SmbFileChooserDialog.newDialog(context, "**.***.*.**", authenticator)
Toast.makeText(context, exception.getMessage(), Toast.LENGTH_LONG).show();
return true;
})
.build()
.show();
```

Expand All @@ -96,19 +95,45 @@ SmbFileChooserDialog.newDialog(context, "**.***.*.**", authenticator)
})
.enableDpad(/*enables Dpad controls (mainly fot Android TVs)*/ true)
.cancelOnTouchOutside(true)
.setTheme(R.style.FileChooserStyle)
.setAdapterSetter(adapter -> {
adapter.overrideGetView(
(file, isSelected, convertView, parent, inflater) -> {
// inflate and return view. SmbFile should not be accessed on the main thread!
return convertView;
}, (file, isSelected, view) -> {
// modify view. only available if SmbFileChooserDialog is being used.
});
})
```

## What's Different?

I replaced all methods "with___()" with "set___()"! And, use static method "newDialog(context)" instead of a constructor.

- you can also pass Strings instead of Resource id. **if Resource id was set, it will take priority over Strings!**
- there are no public constructors. Instead use static methods:
```java
FileChooserDialog.newDialog(context)
```
- when multiple files are selected, a new listener is called:
```java
.setOptionResources(0, 0, 0, 0)
.setOptionResources("new folder", "delete", "cancel", "ok")
FileChooserDialog.setOnSelectedListener(files -> {
ArrayList<String> paths = new ArrayList<>();
for (File file : files) {
paths.add(file.getPath());
}

new AlertDialog.Builder(ctx)
.setTitle(files.size() + " files selected:")
.setAdapter(new ArrayAdapter<>(ctx,
android.R.layout.simple_expandable_list_item_1, paths), null)
.create()
.show();
});
```
- there's no _**titleFollowsDir**_ option, and _**displayPath**_ is false by default

For more information please refere to the [upstream repo](https://github.com/hedzr/android-file-chooser).
For more information please refer to the [upstream repo](https://github.com/hedzr/android-file-chooser).

## License

Expand Down
23 changes: 22 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
Expand Down Expand Up @@ -36,8 +37,16 @@ android {
versionName project.VERSION_NAME
}
buildTypes {
debug {
minifyEnabled true
shrinkResources false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
shrinkResources true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -49,15 +58,27 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
lintConfig rootProject.file('lint.xml')
quiet true
abortOnError false
ignoreWarnings true
disable 'InvalidPackage' // Some libraries have issues with this.
disable 'OldTargetApi' // Lint gives this warning but SDK 20 would be Android L Beta.
disable 'IconDensities' // For testing purpose. This is safe to remove.
checkReleaseBuilds false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':library')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'eu.agno3.jcifs:jcifs-ng:2.1.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

/** LeakCanary - https://github.com/square/leakcanary */
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".AboutActivity"
android:label="@string/title_activity_about"
android:icon="@mipmap/ic_launcher"
android:parentActivityName=".ChooseFileActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.obsez.android.lib.smbfilechooser.demo.ChooseFileActivity"/>
</activity>

<activity
android:name=".ChooseFileActivity"
android:label="@string/app_name"
Expand All @@ -22,6 +33,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.obsez.android.lib.smbfilechooser.demo

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.snackbar.Snackbar
import com.obsez.android.lib.smbfilechooser.internals.UiUtil
import kotlinx.android.synthetic.main.activity_about.*

class AboutActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
setSupportActionBar(findViewById<Toolbar>(R.id.toolbar))
(findViewById<FloatingActionButton>(R.id.fab)).setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)

// TODO add general, readme, license tabs...
setupUi()
}

private fun setupUi() {
setupRecyclerView(findViewById<RecyclerView>(R.id.recyclerView1))
}

private fun setupRecyclerView(rv: RecyclerView) {
rv.apply {
val linearLayoutManager = object : LinearLayoutManager(this.context) {
override fun getExtraLayoutSpace(state: RecyclerView.State): Int {
return UiUtil.dip2px(56)
}
}
this.layoutManager = linearLayoutManager //LinearLayoutManager(cxt)

this.addItemDecoration(DividerItemDecoration(this.context, DividerItemDecoration.HORIZONTAL))
//this.addDivider(R.drawable.recycler_view_divider)

this.itemAnimator = DefaultItemAnimator() //adapter.animator
//val animation = AnimationUtils.loadLayoutAnimation(this.context, RvTool.layoutAnimationResId)
//this.layoutAnimation = animation

this.adapter = MainAdapter(this@AboutActivity, aboutItems)
}
}

class MainAdapter(private val ctx: AppCompatActivity, items: List<Items>) : RecyclerView.Adapter<MainAdapter.ViewHolder>() {

var plainItems: MutableList<Item> = mutableListOf()

init {
for (it in items) {
if (it.items.isNotEmpty())
it.items[0].catalog = it.title
plainItems.addAll(it.items)
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
//return ViewHolder(TextView(parent.context))
return ViewHolder(LayoutInflater.from(ctx).inflate(R.layout.li_about_item, parent, false)) { _, holder ->
if (holder.mValueView.tag != null && holder.mValueView.tag is String) {
val link: String = holder.mValueView.tag as String
when {
link.startsWith("mailto:") -> ctx.startActivity(Intent(Intent.ACTION_SENDTO, Uri.parse(link)))
link.startsWith("tel:") -> ctx.startActivity(Intent(Intent.ACTION_DIAL, Uri.parse(link)))
link.startsWith("market:") -> {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse(link))
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
try {
ctx.startActivity(intent)
} catch (e: ActivityNotFoundException) {
ctx.startActivity(Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + ctx.getPackageName())))
}
}
else -> ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
}
}
}
}

override fun getItemCount(): Int {
return plainItems.size
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val it = plainItems[position]
holder.mTitleView.text = it.title
holder.mSubTitleView.text = it.subTitle
holder.mValueView.text = it.value

if (it.subTitle.isBlank()) {
holder.mSubTitleView.visibility = View.GONE
} else {
holder.mSubTitleView.visibility = View.VISIBLE
}
if (!it.catalog.isNullOrBlank()) {
holder.mCatalogView.text = it.catalog
holder.mCatalogView.visibility = View.VISIBLE
} else {
holder.mCatalogView.visibility = View.GONE
}

//holder.mValueView.isClickable = !it.valueLink.isBlank()
holder.mValueView.tag = it.valueLink
//holder.mIconView.text = it.title
}

class ViewHolder(view: View, clicking: ((v: View, holder: MainAdapter.ViewHolder) -> Unit)? = null) : RecyclerView.ViewHolder(view) {
internal var mTitleView = view.findViewById<TextView>(R.id.title)
internal var mSubTitleView = view.findViewById<TextView>(R.id.sub_title)
internal var mValueView = view.findViewById<TextView>(R.id.value)
internal var mCatalogView = view.findViewById<TextView>(R.id.catalog)
internal var mIconView = view.findViewById<ImageView>(R.id.icon)

init {
// mValueView.setOnClickListener {
// clicking?.invoke(it, this)
// }
view.findViewById<View>(R.id.row)?.setOnClickListener {
clicking?.invoke(it, this)
}
}
}
}

companion object {
val aboutItems = listOf(
Items("Information", listOf(
Item("Homepage", "Goto", "https://github.com/hedzr/android-file-chooser"),
Item("Issues", "Report to us", "https://github.com/hedzr/android-file-chooser/issues/new"),
Item("License", "Apache 2.0", "https://github.com/hedzr/android-file-chooser/blob/master/LICENSE"),
Item("Rate me", "Like!", "market://details?id=" + "com.obsez.android.lib.filechooser")

)),
Items("Credits", listOf(
Item("Hedzr Yeh", "Email", "mailto:hedzrz@gmail.com", "Maintainer"),
Item("Guiorgy Potskhishvili", "Email", "mailto:guiorgy123@gmail.com", "Maintainer"),
Item("iqbalhood", "Email", "iqbalhood@gmail.com", "Logo and banner maker"),
Item("More Contributors", "Goto", "https://github.com/hedzr/android-file-chooser#Acknowledges", "and supporters")
))
)
}
}

class Items(var title: String, var items: List<Item>)
class Item(var title: String, var value: String, var valueLink: String = "", var subTitle: String = "", var catalog: String? = null)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.obsez.android.lib.smbfilechooser.demo;

import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -50,7 +52,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand All @@ -66,7 +67,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
//if (id == R.id.action_settings) {
// return true;
//}

if (id == R.id.action_about) {
startActivity(new Intent(this, AboutActivity.class));
return true;
}
if (id == R.id.action_gh) {
startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/hedzr/android-file-chooser")));
return true;
}

Expand Down
Loading

0 comments on commit b51f0bb

Please sign in to comment.