add: script files and dirs collapsing support
This commit is contained in:
@@ -74,11 +74,21 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
|||||||
int h = mFabs[0].getHeight();
|
int h = mFabs[0].getHeight();
|
||||||
for (int i = 0; i < mFabContainers.length; i++) {
|
for (int i = 0; i < mFabContainers.length; i++) {
|
||||||
animateY(mFabContainers[i], -(h + mInterval) * (i + 1), null);
|
animateY(mFabContainers[i], -(h + mInterval) * (i + 1), null);
|
||||||
|
rotate(mFabs[i]);
|
||||||
}
|
}
|
||||||
mExpanded = true;
|
mExpanded = true;
|
||||||
mState.onNext(true);
|
mState.onNext(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rotate(FloatingActionButton fab) {
|
||||||
|
fab.setRotation(0);
|
||||||
|
fab.animate()
|
||||||
|
.rotation(360)
|
||||||
|
.setDuration(mDuration)
|
||||||
|
.setInterpolator(mInterpolator)
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void animateY(View view, float y, Animator.AnimatorListener l) {
|
private void animateY(View view, float y, Animator.AnimatorListener l) {
|
||||||
view.animate()
|
view.animate()
|
||||||
@@ -98,6 +108,7 @@ public class FloatingActionMenu extends FrameLayout implements View.OnClickListe
|
|||||||
});
|
});
|
||||||
for (int i = 1; i < mFabContainers.length; i++) {
|
for (int i = 1; i < mFabContainers.length; i++) {
|
||||||
animateY(mFabContainers[i], 0, null);
|
animateY(mFabContainers[i], 0, null);
|
||||||
|
rotate(mFabs[i]);
|
||||||
}
|
}
|
||||||
mExpanded = false;
|
mExpanded = false;
|
||||||
mState.onNext(false);
|
mState.onNext(false);
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package com.stardust.scriptdroid.ui.main.scripts;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -21,7 +21,6 @@ import com.stardust.scriptdroid.R;
|
|||||||
import com.stardust.scriptdroid.script.ScriptFile;
|
import com.stardust.scriptdroid.script.ScriptFile;
|
||||||
import com.stardust.scriptdroid.script.Scripts;
|
import com.stardust.scriptdroid.script.Scripts;
|
||||||
import com.stardust.scriptdroid.script.StorageFileProvider;
|
import com.stardust.scriptdroid.script.StorageFileProvider;
|
||||||
import com.stardust.scriptdroid.tool.SimpleObserver;
|
|
||||||
import com.stardust.scriptdroid.ui.common.ScriptLoopDialog;
|
import com.stardust.scriptdroid.ui.common.ScriptLoopDialog;
|
||||||
import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
||||||
import com.stardust.scriptdroid.ui.viewmodel.ScriptList;
|
import com.stardust.scriptdroid.ui.viewmodel.ScriptList;
|
||||||
@@ -30,19 +29,15 @@ import com.stardust.widget.BindableViewHolder;
|
|||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.ObservableSource;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.annotations.NonNull;
|
import io.reactivex.annotations.NonNull;
|
||||||
import io.reactivex.functions.Action;
|
|
||||||
import io.reactivex.functions.BiConsumer;
|
import io.reactivex.functions.BiConsumer;
|
||||||
import io.reactivex.functions.Consumer;
|
import io.reactivex.functions.Consumer;
|
||||||
import io.reactivex.functions.Function;
|
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,6 +51,7 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
void onScriptFileClick(View view, ScriptFile file);
|
void onScriptFileClick(View view, ScriptFile file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int positionOfCategoryDir = 0;
|
||||||
private ScriptList mScriptList = new ScriptList();
|
private ScriptList mScriptList = new ScriptList();
|
||||||
private RecyclerView mScriptListView;
|
private RecyclerView mScriptListView;
|
||||||
private ScriptListAdapter mScriptListAdapter = new ScriptListAdapter();
|
private ScriptListAdapter mScriptListAdapter = new ScriptListAdapter();
|
||||||
@@ -64,6 +60,8 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
private ScriptFile mSelectedScriptFile;
|
private ScriptFile mSelectedScriptFile;
|
||||||
private StorageFileProvider mStorageFileProvider;
|
private StorageFileProvider mStorageFileProvider;
|
||||||
private boolean mDirSortMenuShowing = false;
|
private boolean mDirSortMenuShowing = false;
|
||||||
|
private boolean mDirsCollapsed;
|
||||||
|
private boolean mFilesCollapsed;
|
||||||
|
|
||||||
public ScriptListView(Context context) {
|
public ScriptListView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -81,6 +79,8 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
|
|
||||||
public void setCurrentDirectory(ScriptFile currentDirectory) {
|
public void setCurrentDirectory(ScriptFile currentDirectory) {
|
||||||
mCurrentDirectory = currentDirectory;
|
mCurrentDirectory = currentDirectory;
|
||||||
|
mDirsCollapsed = false;
|
||||||
|
mFilesCollapsed = false;
|
||||||
loadScriptList();
|
loadScriptList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +94,7 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void goBack() {
|
public void goBack() {
|
||||||
mCurrentDirectory = mCurrentDirectory.getParentFile();
|
setCurrentDirectory(mCurrentDirectory.getParentFile());
|
||||||
loadScriptList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
@@ -115,7 +114,7 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
@Override
|
@Override
|
||||||
public int getSpanSize(int position) {
|
public int getSpanSize(int position) {
|
||||||
//For directories
|
//For directories
|
||||||
if (position >= 1 && position <= mScriptList.directoryCount()) {
|
if (position > positionOfCategoryDir && position < positionOfCategoryFile()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//For files and category
|
//For files and category
|
||||||
@@ -125,6 +124,11 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
mScriptListView.setLayoutManager(manager);
|
mScriptListView.setLayoutManager(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int positionOfCategoryFile() {
|
||||||
|
if (mDirsCollapsed)
|
||||||
|
return 1;
|
||||||
|
return mScriptList.directoryCount() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
private void loadScriptList() {
|
private void loadScriptList() {
|
||||||
mScriptList.clear();
|
mScriptList.clear();
|
||||||
@@ -140,16 +144,13 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
.doOnSuccess(new Consumer<ScriptList>() {
|
.doOnSuccess(new Consumer<ScriptList>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(@NonNull ScriptList list) throws Exception {
|
public void accept(@NonNull ScriptList list) throws Exception {
|
||||||
Log.d("SSS", "before sort:" + Thread.currentThread());
|
|
||||||
list.sort();
|
list.sort();
|
||||||
Log.d("SSS", "after sort:" + Thread.currentThread());
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(new Consumer<ScriptList>() {
|
.subscribe(new Consumer<ScriptList>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(@NonNull ScriptList list) throws Exception {
|
public void accept(@NonNull ScriptList list) throws Exception {
|
||||||
Log.d("SSS", "notifyDataSetChanged:" + Thread.currentThread());
|
|
||||||
mScriptList = list;
|
mScriptList = list;
|
||||||
mScriptListAdapter.notifyDataSetChanged();
|
mScriptListAdapter.notifyDataSetChanged();
|
||||||
setRefreshing(false);
|
setRefreshing(false);
|
||||||
@@ -266,24 +267,26 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||||
|
int positionOfCategoryFile = positionOfCategoryFile();
|
||||||
BindableViewHolder bindableViewHolder = (BindableViewHolder) holder;
|
BindableViewHolder bindableViewHolder = (BindableViewHolder) holder;
|
||||||
if (position == 0 || position == mScriptList.directoryCount() + 1) {
|
if (position == positionOfCategoryDir || position == positionOfCategoryFile) {
|
||||||
bindableViewHolder.bind(position == 0, position);
|
bindableViewHolder.bind(position == positionOfCategoryDir, position);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (position <= mScriptList.directoryCount()) {
|
if (position < positionOfCategoryFile) {
|
||||||
bindableViewHolder.bind(mScriptList.getDir(position - 1), position);
|
bindableViewHolder.bind(mScriptList.getDir(position - 1), position);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bindableViewHolder.bind(mScriptList.getFile(position - mScriptList.directoryCount() - 2), position);
|
bindableViewHolder.bind(mScriptList.getFile(position - positionOfCategoryFile() - 1), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (position == 0 || position == mScriptList.directoryCount() + 1) {
|
int positionOfCategoryFile = positionOfCategoryFile();
|
||||||
|
if (position == positionOfCategoryDir || position == positionOfCategoryFile) {
|
||||||
return VIEW_TYPE_CATEGORY;
|
return VIEW_TYPE_CATEGORY;
|
||||||
}
|
}
|
||||||
if (position <= mScriptList.directoryCount()) {
|
if (position < positionOfCategoryFile) {
|
||||||
return VIEW_TYPE_DIRECTORY;
|
return VIEW_TYPE_DIRECTORY;
|
||||||
}
|
}
|
||||||
return VIEW_TYPE_FILE;
|
return VIEW_TYPE_FILE;
|
||||||
@@ -291,7 +294,14 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return mScriptList.count() + 2;
|
int count = 0;
|
||||||
|
if (!mDirsCollapsed) {
|
||||||
|
count += mScriptList.directoryCount();
|
||||||
|
}
|
||||||
|
if (!mFilesCollapsed) {
|
||||||
|
count += mScriptList.fileCount();
|
||||||
|
}
|
||||||
|
return count + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,11 +334,11 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
mDesc.setText(PFile.getHumanReadableSize(file.length()));
|
mDesc.setText(PFile.getHumanReadableSize(file.length()));
|
||||||
if (file.getType() == ScriptFile.TYPE_JAVA_SCRIPT) {
|
if (file.getType() == ScriptFile.TYPE_JAVA_SCRIPT) {
|
||||||
mFirstChar.setText("J");
|
mFirstChar.setText("J");
|
||||||
mFirstCharBackground.setColor(getResources().getColor(R.color.color_j));
|
mFirstCharBackground.setColor(ResourcesCompat.getColor(getResources(), R.color.color_j, getContext().getTheme()));
|
||||||
mEdit.setVisibility(VISIBLE);
|
mEdit.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
mFirstChar.setText("R");
|
mFirstChar.setText("R");
|
||||||
mFirstCharBackground.setColor(getResources().getColor(R.color.color_r));
|
mFirstCharBackground.setColor(ResourcesCompat.getColor(getResources(), R.color.color_r, getContext().getTheme()));
|
||||||
mEdit.setVisibility(GONE);
|
mEdit.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,6 +419,9 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
@BindView(R.id.back)
|
@BindView(R.id.back)
|
||||||
ImageView mGoBack;
|
ImageView mGoBack;
|
||||||
|
|
||||||
|
@BindView(R.id.collapse)
|
||||||
|
ImageView mArrow;
|
||||||
|
|
||||||
private boolean mIsDir;
|
private boolean mIsDir;
|
||||||
|
|
||||||
CategoryViewHolder(View itemView) {
|
CategoryViewHolder(View itemView) {
|
||||||
@@ -425,6 +438,11 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
} else {
|
} else {
|
||||||
mGoBack.setVisibility(GONE);
|
mGoBack.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
|
if (isDirCategory) {
|
||||||
|
mArrow.setRotation(mDirsCollapsed ? -90 : 0);
|
||||||
|
} else {
|
||||||
|
mArrow.setRotation(mFilesCollapsed ? -90 : 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.order)
|
@OnClick(R.id.order)
|
||||||
@@ -458,5 +476,15 @@ public class ScriptListView extends SwipeRefreshLayout implements SwipeRefreshLa
|
|||||||
goBack();
|
goBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.title_container)
|
||||||
|
void collapseOrExpand() {
|
||||||
|
if (mIsDir) {
|
||||||
|
mDirsCollapsed = !mDirsCollapsed;
|
||||||
|
} else {
|
||||||
|
mFilesCollapsed = !mFilesCollapsed;
|
||||||
|
}
|
||||||
|
mScriptListAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/ic_arrow_drop_down_black_36dp.png
Normal file
BIN
app/src/main/res/drawable/ic_arrow_drop_down_black_36dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 141 B |
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:clipToPadding="false">
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
<android.support.design.widget.AppBarLayout
|
||||||
android:id="@+id/app_bar"
|
android:id="@+id/app_bar"
|
||||||
@@ -46,6 +48,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:clipToPadding="false"
|
||||||
app:layout_anchor="@id/viewpager"
|
app:layout_anchor="@id/viewpager"
|
||||||
app:layout_anchorGravity="bottom|right|end"
|
app:layout_anchorGravity="bottom|right|end"
|
||||||
>
|
>
|
||||||
@@ -55,6 +59,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="right|end|bottom"
|
android:layout_gravity="right|end|bottom"
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:clipToPadding="false"
|
||||||
android:visibility="invisible"/>
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
<com.stardust.theme.widget.ThemeColorFloatingActionButton
|
<com.stardust.theme.widget.ThemeColorFloatingActionButton
|
||||||
|
|||||||
@@ -23,12 +23,12 @@
|
|||||||
android:textColor="#484C4F"
|
android:textColor="#484C4F"
|
||||||
android:textSize="16sp"/>
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
<!-- android:src="@drawable/ic_arrow_drop_down_black" -->
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="16dp"
|
android:layout_width="16dp"
|
||||||
android:layout_height="16dp"
|
android:layout_height="16dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
|
android:src="@drawable/ic_arrow_drop_down_black_36dp"
|
||||||
android:tint="#484C4F"/>
|
android:tint="#484C4F"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|right|end"
|
android:layout_gravity="bottom|right|end"
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:clipToPadding="false"
|
||||||
android:gravity="end|right"
|
android:gravity="end|right"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/title_container"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
android:id="@+id/collapse"
|
||||||
android:layout_width="16dp"
|
android:layout_width="16dp"
|
||||||
android:layout_height="16dp"
|
android:layout_height="16dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
|||||||
Reference in New Issue
Block a user