Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
codekidX committed Jul 8, 2018
2 parents a1c8028 + cb8ac0f commit e34654b
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'

compile project (':storagechooser')
implementation project (':storagechooser')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 01 10:45:35 IST 2017
#Sun Jul 08 10:09:20 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
12 changes: 6 additions & 6 deletions storagechooser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.github.markushi:circlebutton:1.1'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.github.markushi:circlebutton:1.1'
testImplementation 'junit:junit:4.12'
}

task javadoc(type: Javadoc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.codekidlabs.storagechooser.fragments;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.drawable.Animatable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
Expand All @@ -27,6 +29,7 @@
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -72,6 +75,7 @@ public class SecondaryChooserFragment extends android.app.DialogFragment {
private EditText mFolderNameEditText;
private CircleButton mMultipleOnSelectButton;
private RelativeLayout mNewFolderView;
private ProgressBar mFilesProgress;
private String mBundlePath;
private ListView listView;
private boolean isOpen;
Expand Down Expand Up @@ -121,7 +125,7 @@ public void onClick(View view) {
}
};
private boolean keyboardToggle;
private String TAG = "StorageChooser";
private final String TAG = "StorageChooser";
private boolean isFilePicker;
private View.OnClickListener mCreateButtonClickListener = new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -174,7 +178,7 @@ public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, lon
}
};

// ================ CLICK LISTENER END ==================

private View.OnClickListener mBackButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -204,6 +208,8 @@ public void onItemClick(AdapterView<?> adapterView, View view, final int i, long
}
};

// ================ CLICK LISTENER END ==================

private void showAddFolderView() {
mNewFolderView.setVisibility(View.VISIBLE);
Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.anim_new_folder_view);
Expand Down Expand Up @@ -259,32 +265,43 @@ public void hideKeyboard() {

private void performBackAction() {
int slashIndex = theSelectedPath.lastIndexOf("/");
if (MODE_MULTIPLE) {
bringBackSingleMode();
secondaryChooserAdapter.notifyDataSetChanged();

} else {
if (!mConfig.isSkipOverview()) {
if (theSelectedPath.equals(mBundlePath)) {
SecondaryChooserFragment.this.dismiss();

//delay until close animation ends
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
dissmissDialog(FLAG_DISSMISS_INIT_DIALOG);
}
}, 200);
if(slashIndex != -1) {
if (MODE_MULTIPLE) {
bringBackSingleMode();
secondaryChooserAdapter.notifyDataSetChanged();

} else {
if (!mConfig.isSkipOverview()) {
if (theSelectedPath.equals(mBundlePath)) {
SecondaryChooserFragment.this.dismiss();

//delay until close animation ends
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
dissmissDialog(FLAG_DISSMISS_INIT_DIALOG);
}
}, 200);
} else {
theSelectedPath = theSelectedPath.substring(0, slashIndex);
StorageChooser.LAST_SESSION_PATH = theSelectedPath;
populateList("");
}
} else {
theSelectedPath = theSelectedPath.substring(0, slashIndex);
Log.e("SCLib", "Performing back action: " + theSelectedPath);
StorageChooser.LAST_SESSION_PATH = theSelectedPath;
populateList("");
dissmissDialog(FLAG_DISSMISS_NORMAL);
}
} else {
dissmissDialog(FLAG_DISSMISS_NORMAL);
}
} else {
// let's just say that there is no / in the path at any given point
// which is hard to imagine but.. what to do at that time ?
// we set it to bundle path until the issue is totally investigated
// TODO - dig deep about this condition !
theSelectedPath = mBundlePath;
StorageChooser.LAST_SESSION_PATH = theSelectedPath;
populateList("");
}

}

private void dissmissDialog(int flag) {
Expand Down Expand Up @@ -327,6 +344,7 @@ private View getLayout(LayoutInflater inflater, ViewGroup container) {
mContext = getActivity().getApplicationContext();
mResourceUtil = new ResourceUtil(mContext);
mLayout = inflater.inflate(R.layout.custom_storage_list, container, false);

initListView(mContext, mLayout, mConfig.isShowMemoryBar());

initUI();
Expand Down Expand Up @@ -432,6 +450,12 @@ private void initNewFolderView() {
private void initListView(Context context, View view, boolean shouldShowMemoryBar) {
listView = view.findViewById(R.id.storage_list_view);
mPathChosen = view.findViewById(R.id.path_chosen);
mFilesProgress = mLayout.findViewById(R.id.files_loader);
mFilesProgress.setIndeterminate(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mFilesProgress.setIndeterminateTintList(ColorStateList.valueOf(scheme[Theme.OVERVIEW_MEMORYBAR_INDEX]));
}

mBundlePath = this.getArguments().getString(DiskUtil.SC_PREFERENCE_KEY);
isFilePicker = this.getArguments().getBoolean(DiskUtil.SC_CHOOSER_FLAG, false);
populateList(mBundlePath);
Expand All @@ -452,7 +476,7 @@ private void initListView(Context context, View view, boolean shouldShowMemoryBa

/**
* handles actions in multiple mode
* like adding to list and setting backgroud color
* like adding to list and setting background color
*
* @param i is position of list clicked
*/
Expand Down Expand Up @@ -565,22 +589,60 @@ private void populateList(String path) {

if (isFilePicker) {
if (mConfig.isCustomFilter()) {
UniversalFileFilter universalFileFilter =
new UniversalFileFilter(mConfig.isCustomFilter(), mConfig.getCustomEnum());
volumeList = new File(theSelectedPath)
.listFiles(universalFileFilter);
// we need to start a async task here because the filter loops through all files
// and if the files are more it'll take ages and it'll cause ANR as this is
// running on main thread
new FileFilterTask(mConfig, true).execute();
} else {
if (mConfig.getSingleFilter() != null) {
volumeList = new File(theSelectedPath).listFiles(new UniversalFileFilter(mConfig.getSingleFilter()));
new FileFilterTask(mConfig, false).execute();
} else {
volumeList = fileUtil.listFilesInDir(theSelectedPath);
setAdapterList(volumeList);
refreshList();
setBundlePathOnUpdate();
}
}
} else {
volumeList = fileUtil.listFilesAsDir(theSelectedPath);
setAdapterList(volumeList);
refreshList();
setBundlePathOnUpdate();
}

Log.e("SCLib", theSelectedPath);
playTheAddressBarAnimation();
}

/**
* setBundlePathOnUpdate sets the mBundlePath on each list element change. Bundle path is used
* to change the main working directory of chooser.
*/
public void setBundlePathOnUpdate() {
if (mConfig.isResumeSession() && StorageChooser.LAST_SESSION_PATH != null) {
if (StorageChooser.LAST_SESSION_PATH.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) {
mBundlePath = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
mBundlePath = StorageChooser.LAST_SESSION_PATH.substring(StorageChooser.LAST_SESSION_PATH.indexOf("/", 16), StorageChooser.LAST_SESSION_PATH.length());
}
}
}

/**
* Refreshes the list LOL. It checks if adapter is null and notifies change of list on each
* file list update.
*/
public void refreshList() {
if (secondaryChooserAdapter != null) {
secondaryChooserAdapter.notifyDataSetChanged();
}
}

/**
* Accepts a file list and sets it for use of storage chooser. Called before all refreshList()
*
* @param volumeList File list to be shown in storage chooser
*/
public void setAdapterList(File[] volumeList) {
if (volumeList != null) {
for (File f : volumeList) {
if (mConfig.isShowHidden()) {
Expand All @@ -601,22 +663,6 @@ public int compare(String s1, String s2) {
} else {
customStoragesList.clear();
}


if (secondaryChooserAdapter != null) {
secondaryChooserAdapter.notifyDataSetChanged();
}

playTheAddressBarAnimation();

if (mConfig.isResumeSession() && StorageChooser.LAST_SESSION_PATH != null) {
if (StorageChooser.LAST_SESSION_PATH.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) {
mBundlePath = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
Log.e("Bundle_Path_Length", StorageChooser.LAST_SESSION_PATH);
mBundlePath = StorageChooser.LAST_SESSION_PATH.substring(StorageChooser.LAST_SESSION_PATH.indexOf("/", 16), StorageChooser.LAST_SESSION_PATH.length());
}
}
}

/**
Expand Down Expand Up @@ -690,7 +736,10 @@ private void playTheMultipleButtonEndAnimation() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog d = StorageChooser.dialog;
d.setContentView(getLayout(LayoutInflater.from(getActivity().getApplicationContext()), mContainer));
if(getActivity() != null) {
d.setContentView(getLayout(LayoutInflater.from(getActivity().getApplicationContext()), mContainer));
}

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
Expand Down Expand Up @@ -738,4 +787,45 @@ private boolean validateFolderName() {
}
return true;
}

@SuppressLint("StaticFieldLeak")
class FileFilterTask extends AsyncTask<Void, String, Boolean> {

private Config mConfig;
private boolean isMultiple;
private File[] fileList;

FileFilterTask(Config mConfig, boolean isMultiple) {
this.mConfig = mConfig;
this.isMultiple = isMultiple;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
mFilesProgress.setVisibility(View.VISIBLE);
}

@Override
protected Boolean doInBackground(Void... voids) {
if (isMultiple) {
UniversalFileFilter universalFileFilter =
new UniversalFileFilter(mConfig.isCustomFilter(), mConfig.getCustomEnum());
fileList = new File(theSelectedPath)
.listFiles(universalFileFilter);
} else {
fileList = new File(theSelectedPath).listFiles(new UniversalFileFilter(mConfig.getSingleFilter()));
}
return true;
}

@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mFilesProgress.setVisibility(View.INVISIBLE);
setAdapterList(this.fileList);
refreshList();
setBundlePathOnUpdate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
android:listSelector="@drawable/ripple"
android:longClickable="true" />

<ProgressBar
android:id="@+id/files_loader"
style="?android:progressBarStyleHorizontal"
android:layout_centerInParent="true"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:visibility="visible"
/>


<!-- create folder view -->
<RelativeLayout
Expand Down
Loading

0 comments on commit e34654b

Please sign in to comment.