@ -0,0 +1,196 @@ |
|||||||
|
/* |
||||||
|
* Clover - 4chan browser https://github.com/Floens/Clover/
|
||||||
|
* Copyright (C) 2014 Floens |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
package org.floens.chan.ui.fragment; |
||||||
|
|
||||||
|
import android.app.DialogFragment; |
||||||
|
import android.os.Bundle; |
||||||
|
import android.view.LayoutInflater; |
||||||
|
import android.view.View; |
||||||
|
import android.view.ViewGroup; |
||||||
|
import android.widget.ArrayAdapter; |
||||||
|
import android.widget.FrameLayout; |
||||||
|
import android.widget.ListView; |
||||||
|
import android.widget.TextView; |
||||||
|
|
||||||
|
import org.floens.chan.R; |
||||||
|
import org.floens.chan.utils.ThemeHelper; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class FolderPickFragment extends DialogFragment { |
||||||
|
private TextView statusPath; |
||||||
|
private ListView listView; |
||||||
|
private ArrayAdapter<String> adapter; |
||||||
|
boolean hasParent = false; |
||||||
|
|
||||||
|
private FolderPickListener listener; |
||||||
|
private File currentPath; |
||||||
|
private List<File> directories; |
||||||
|
private FrameLayout okButton; |
||||||
|
private TextView okButtonIcon; |
||||||
|
|
||||||
|
public static FolderPickFragment newInstance(FolderPickListener listener, File startingPath) { |
||||||
|
FolderPickFragment fragment = new FolderPickFragment(); |
||||||
|
fragment.listener = listener; |
||||||
|
fragment.currentPath = startingPath; |
||||||
|
return fragment; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCreate(Bundle savedInstanceState) { |
||||||
|
super.onCreate(savedInstanceState); |
||||||
|
|
||||||
|
if (listener == null || currentPath == null) { |
||||||
|
dismiss(); |
||||||
|
} |
||||||
|
|
||||||
|
setStyle(STYLE_NO_TITLE, 0); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup unused, Bundle savedInstanceState) { |
||||||
|
if (listener == null || currentPath == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
View container = inflater.inflate(R.layout.folder_pick, null); |
||||||
|
|
||||||
|
statusPath = (TextView) container.findViewById(R.id.folder_status); |
||||||
|
listView = (ListView) container.findViewById(R.id.folder_list); |
||||||
|
okButton = (FrameLayout) container.findViewById(R.id.pick_ok); |
||||||
|
okButtonIcon = (TextView) container.findViewById(R.id.pick_ok_icon); |
||||||
|
|
||||||
|
container.findViewById(R.id.pick_back).setOnClickListener(new View.OnClickListener() { |
||||||
|
@Override |
||||||
|
public void onClick(View v) { |
||||||
|
dismiss(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
okButton.findViewById(R.id.pick_ok).setOnClickListener(new View.OnClickListener() { |
||||||
|
@Override |
||||||
|
public void onClick(View v) { |
||||||
|
listener.folderPicked(currentPath); |
||||||
|
dismiss(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
if (!ThemeHelper.getInstance().getTheme().isLightTheme) { |
||||||
|
((TextView) container.findViewById(R.id.pick_back_icon)).setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_cancel_dark, 0, 0, 0); |
||||||
|
((TextView) container.findViewById(R.id.pick_ok_icon)).setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_done_dark, 0, 0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
adapter = new ArrayAdapter<String>(inflater.getContext(), 0) { |
||||||
|
@Override |
||||||
|
public View getView(final int position, View convertView, ViewGroup parent) { |
||||||
|
if (convertView == null) { |
||||||
|
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, null); |
||||||
|
} |
||||||
|
TextView text = (TextView) convertView; |
||||||
|
|
||||||
|
String name = getItem(position); |
||||||
|
|
||||||
|
text.setText(name); |
||||||
|
|
||||||
|
text.setOnClickListener(new View.OnClickListener() { |
||||||
|
@Override |
||||||
|
public void onClick(View v) { |
||||||
|
if (hasParent) { |
||||||
|
if (position == 0) { |
||||||
|
File parent = currentPath.getParentFile(); |
||||||
|
moveTo(parent); |
||||||
|
} else if (position > 0 && position <= directories.size()) { |
||||||
|
File dir = directories.get(position - 1); |
||||||
|
moveTo(dir); |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (position >= 0 && position < directories.size()) { |
||||||
|
File dir = directories.get(position); |
||||||
|
moveTo(dir); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return text; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
listView.setAdapter(adapter); |
||||||
|
|
||||||
|
moveTo(currentPath); |
||||||
|
|
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean validPath(File path) { |
||||||
|
return path != null && path.isDirectory() && path.canRead() && path.canWrite(); |
||||||
|
} |
||||||
|
|
||||||
|
private void moveTo(File path) { |
||||||
|
if (path != null && path.isDirectory()) { |
||||||
|
File[] listFiles = path.listFiles(); |
||||||
|
if (listFiles != null) { |
||||||
|
currentPath = path; |
||||||
|
statusPath.setText(currentPath.getAbsolutePath()); |
||||||
|
List<File> dirs = new ArrayList<>(); |
||||||
|
for (File file : path.listFiles()) { |
||||||
|
if (file.isDirectory()) { |
||||||
|
dirs.add(file); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
setDirs(dirs); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
validState(); |
||||||
|
} |
||||||
|
|
||||||
|
private void validState() { |
||||||
|
if (validPath(currentPath)) { |
||||||
|
okButton.setEnabled(true); |
||||||
|
okButtonIcon.setEnabled(true); |
||||||
|
} else { |
||||||
|
okButton.setEnabled(false); |
||||||
|
okButtonIcon.setEnabled(false); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void setDirs(List<File> dirs) { |
||||||
|
directories = dirs; |
||||||
|
adapter.clear(); |
||||||
|
|
||||||
|
if (currentPath.getParent() != null) { |
||||||
|
adapter.add(".."); |
||||||
|
hasParent = true; |
||||||
|
} else { |
||||||
|
hasParent = false; |
||||||
|
} |
||||||
|
for (File file : dirs) { |
||||||
|
adapter.add(file.getName()); |
||||||
|
} |
||||||
|
adapter.notifyDataSetChanged(); |
||||||
|
} |
||||||
|
|
||||||
|
public static interface FolderPickListener { |
||||||
|
public void folderPicked(File path); |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 438 B |
After Width: | Height: | Size: 353 B |
After Width: | Height: | Size: 328 B |
After Width: | Height: | Size: 272 B |
After Width: | Height: | Size: 513 B |
After Width: | Height: | Size: 415 B |
After Width: | Height: | Size: 567 B |
After Width: | Height: | Size: 574 B |
@ -0,0 +1,95 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?><!-- |
||||||
|
Clover - 4chan browser https://github.com/Floens/Clover/ |
||||||
|
Copyright (C) 2014 Floens |
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU General Public License as published by |
||||||
|
the Free Software Foundation, either version 3 of the License, or |
||||||
|
(at your option) any later version. |
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU General Public License for more details. |
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License |
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||||
|
--> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:minHeight="200dp" |
||||||
|
android:minWidth="320dp" |
||||||
|
android:orientation="vertical"> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:baselineAligned="false" |
||||||
|
android:divider="?android:attr/dividerVertical" |
||||||
|
android:dividerPadding="12dp" |
||||||
|
android:orientation="horizontal" |
||||||
|
android:showDividers="middle"> |
||||||
|
|
||||||
|
<FrameLayout |
||||||
|
android:id="@+id/pick_back" |
||||||
|
style="?android:actionButtonStyle" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:layout_weight="1"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/pick_back_icon" |
||||||
|
style="?android:actionBarTabTextStyle" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_gravity="center" |
||||||
|
android:drawableLeft="@drawable/ic_action_cancel" |
||||||
|
android:drawablePadding="8dp" |
||||||
|
android:gravity="center_vertical" |
||||||
|
android:paddingRight="20dp" |
||||||
|
android:text="@string/cancel" /> |
||||||
|
</FrameLayout> |
||||||
|
|
||||||
|
<FrameLayout |
||||||
|
android:id="@+id/pick_ok" |
||||||
|
style="?android:actionButtonStyle" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:layout_weight="1"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/pick_ok_icon" |
||||||
|
style="?android:actionBarTabTextStyle" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_gravity="center" |
||||||
|
android:drawableLeft="@drawable/ic_action_done" |
||||||
|
android:drawablePadding="8dp" |
||||||
|
android:gravity="center_vertical" |
||||||
|
android:paddingRight="20dp" |
||||||
|
android:text="@string/folder_pick_ok" /> |
||||||
|
</FrameLayout> |
||||||
|
</LinearLayout> |
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:id="@+id/folder_status" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:gravity="center_vertical" |
||||||
|
android:minHeight="?android:attr/listPreferredItemHeightSmall" |
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" |
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart" |
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSmall" /> |
||||||
|
|
||||||
|
<View |
||||||
|
android:layout_width="fill_parent" |
||||||
|
android:layout_height="3dp" |
||||||
|
android:background="@android:color/darker_gray"/> |
||||||
|
|
||||||
|
<ListView |
||||||
|
android:id="@+id/folder_list" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" /> |
||||||
|
|
||||||
|
</LinearLayout> |