Add preset download dir
This commit is contained in:
1 parent
d86dd3bc06
commit
db893b899d
6 files changed
+77
-13
No files matched your search
@@ -25,11 +25,14 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.DirExplorer;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import java.io.File;
|
||||
|
||||
public class DirPickerActivity extends ToolbarActivity
|
||||
@@ -46,6 +49,7 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
private TextView mPath;
|
||||
@Nullable
|
||||
private DirExplorer mDirExplorer;
|
||||
private View mDefault;
|
||||
@Nullable
|
||||
private View mOk;
|
||||
|
||||
@@ -55,9 +59,10 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
setContentView(R.layout.activity_dir_picker);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
mPath = (TextView) ViewUtils.$$(this, R.id.path);
|
||||
mDirExplorer = (DirExplorer) ViewUtils.$$(this, R.id.dir_explorer);
|
||||
mOk = ViewUtils.$$(this, R.id.ok);
|
||||
mPath = findViewById(R.id.path);
|
||||
mDirExplorer = findViewById(R.id.dir_explorer);
|
||||
mDefault = findViewById(R.id.preset);
|
||||
mOk = findViewById(R.id.ok);
|
||||
|
||||
File file;
|
||||
if (null == savedInstanceState) {
|
||||
@@ -71,6 +76,7 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
|
||||
Ripple.addRipple(mOk, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme));
|
||||
|
||||
mDefault.setOnClickListener(this);
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
mPath.setText(mDirExplorer.getCurrentFile().getPath());
|
||||
@@ -126,7 +132,31 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull View v) {
|
||||
if (mOk == v) {
|
||||
if (mDefault == v) {
|
||||
File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(this, null);
|
||||
File[] dirs = new File[externalFilesDirs.length + 1];
|
||||
dirs[0] = AppConfig.getDefaultDownloadDir();
|
||||
for (int i = 0; i < externalFilesDirs.length; i++) {
|
||||
dirs[i + 1] = new File(externalFilesDirs[i], "download");
|
||||
}
|
||||
|
||||
CharSequence[] items = new CharSequence[dirs.length];
|
||||
items[0] = getString(R.string.default_directory);
|
||||
for (int i = 1; i < items.length; i++) {
|
||||
items[i] = getString(R.string.application_file_directory, i);
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this).setItems(items, (dialog, which) -> {
|
||||
File dir = dirs[which];
|
||||
if (!FileUtils.ensureDirectory(dir)) {
|
||||
Toast.makeText(DirPickerActivity.this, R.string.directory_not_writable, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mDirExplorer != null) {
|
||||
mDirExplorer.setCurrentFile(dir);
|
||||
}
|
||||
}).show();
|
||||
} else if (mOk == v) {
|
||||
if (null == mDirExplorer) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,13 +38,27 @@
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ok"
|
||||
style="?attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:text="@android:string/ok"
|
||||
android:textColor="?attr/colorPrimary"/>
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/preset"
|
||||
style="?attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left"
|
||||
android:text="@string/preset"
|
||||
android:textColor="?attr/colorAccent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ok"
|
||||
style="?attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:text="@android:string/ok"
|
||||
android:textColor="?attr/colorPrimary"/>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
@@ -396,6 +396,11 @@
|
||||
<string name="invalid_host">无效的 host</string>
|
||||
<string name="invalid_ip">无效的 IP</string>
|
||||
|
||||
<!-- DirPickerActivity -->
|
||||
<string name="preset">预设</string>
|
||||
<string name="default_directory">默认目录</string>
|
||||
<string name="application_file_directory">应用文件目录 %d (应用卸载后会被删除)</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">第 %d 页</string>
|
||||
<string name="page_menu_refresh">@string/refresh</string>
|
||||
|
||||
@@ -396,6 +396,11 @@
|
||||
<string name="invalid_host">無效的 host</string>
|
||||
<string name="invalid_ip">無效的 IP</string>
|
||||
|
||||
<!-- DirPickerActivity -->
|
||||
<string name="preset">預設</string>
|
||||
<string name="default_directory">默認目錄</string>
|
||||
<string name="application_file_directory">應用文件目錄 %d (應用卸載後會被刪除)</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">第 %d 頁</string>
|
||||
<string name="page_menu_refresh">@string/refresh</string>
|
||||
|
||||
@@ -395,6 +395,11 @@
|
||||
<string name="invalid_host">無效的 host</string>
|
||||
<string name="invalid_ip">無效的 IP</string>
|
||||
|
||||
<!-- DirPickerActivity -->
|
||||
<string name="preset">預設</string>
|
||||
<string name="default_directory">預設目錄</string>
|
||||
<string name="application_file_directory">應用檔案目錄 %d (應用解除安裝後會被刪除)</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">第 %d 頁</string>
|
||||
<string name="page_menu_refresh">@string/refresh</string>
|
||||
|
||||
@@ -442,6 +442,11 @@
|
||||
<string name="invalid_host">Invalid host</string>
|
||||
<string name="invalid_ip">Invalid IP</string>
|
||||
|
||||
<!-- DirPickerActivity -->
|
||||
<string name="preset">Preset</string>
|
||||
<string name="default_directory">Default directory</string>
|
||||
<string name="application_file_directory">App file directory %d (it will be remove after uninstalling the app)</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">Page %d</string>
|
||||
<string name="page_menu_refresh">@string/refresh</string>
|
||||
|
||||
Reference in new issue
Block a user