Remove legacy file picker
Remove unused settings
This commit is contained in:
10 files changed
+18
-272
No files matched your search
@@ -155,12 +155,6 @@
|
||||
android:label="@string/excluded_languages"
|
||||
android:theme="@style/AppTheme.Toolbar" />
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DirPickerActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:label="@string/dir_picker"
|
||||
android:theme="@style/AppTheme.Toolbar" />
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.FilterActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
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.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
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.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DirPickerActivity extends ToolbarActivity
|
||||
implements View.OnClickListener, DirExplorer.OnChangeDirListener {
|
||||
|
||||
public static final String KEY_FILE_URI = "file_uri";
|
||||
|
||||
public static final String KEY_FILE_PATH = "file_path";
|
||||
|
||||
/*---------------
|
||||
Whole life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private TextView mPath;
|
||||
@Nullable
|
||||
private DirExplorer mDirExplorer;
|
||||
private View mDefault;
|
||||
@Nullable
|
||||
private View mOk;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dir_picker);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
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) {
|
||||
file = onInit();
|
||||
} else {
|
||||
file = onRestore(savedInstanceState);
|
||||
}
|
||||
|
||||
mDirExplorer.setCurrentFile(file);
|
||||
mDirExplorer.setOnChangeDirListener(this);
|
||||
|
||||
Ripple.addRipple(mOk, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme));
|
||||
|
||||
mDefault.setOnClickListener(this);
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
mPath.setText(mDirExplorer.getCurrentFile().getPath());
|
||||
}
|
||||
|
||||
private File onInit() {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
Uri fileUri = intent.getParcelableExtra(KEY_FILE_URI);
|
||||
if (fileUri != null) {
|
||||
return new File(fileUri.getPath());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private File onRestore(@NonNull Bundle savedInstanceState) {
|
||||
String filePath = savedInstanceState.getString(KEY_FILE_PATH);
|
||||
if (null != filePath) {
|
||||
return new File(filePath);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (null != mDirExplorer) {
|
||||
outState.putString(KEY_FILE_PATH, mDirExplorer.getCurrentFile().getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
mPath = null;
|
||||
mDirExplorer = null;
|
||||
mOk = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull View 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 MaterialAlertDialogBuilder(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;
|
||||
}
|
||||
File file = mDirExplorer.getCurrentFile();
|
||||
if (!file.canWrite()) {
|
||||
Toast.makeText(this, R.string.directory_not_writable, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Intent intent = new Intent();
|
||||
intent.setData(Uri.fromFile(file));
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeDir(File dir) {
|
||||
if (null != mPath) {
|
||||
mPath.setText(dir.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@@ -25,14 +24,11 @@ import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.DirPickerActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.takisoft.preferencex.PreferenceFragmentCompat;
|
||||
@@ -41,7 +37,6 @@ public class DownloadFragment extends PreferenceFragmentCompat implements
|
||||
Preference.OnPreferenceChangeListener,
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR = 0;
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
|
||||
|
||||
public static final String KEY_DOWNLOAD_LOCATION = "download_location";
|
||||
@@ -89,39 +84,12 @@ public class DownloadFragment extends PreferenceFragmentCompat implements
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
if (KEY_DOWNLOAD_LOCATION.equals(key)) {
|
||||
showDirPickerDialogL();
|
||||
openDirPickerL();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showDirPickerDialogL() {
|
||||
DialogInterface.OnClickListener listener = (dialog, which) -> {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
openDirPicker();
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEUTRAL:
|
||||
openDirPickerL();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
new MaterialAlertDialogBuilder(requireActivity()).setMessage(R.string.settings_download_pick_dir_l)
|
||||
.setPositiveButton(R.string.settings_download_continue, listener)
|
||||
.setNeutralButton(R.string.settings_download_document, listener)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void openDirPicker() {
|
||||
UniFile uniFile = Settings.getDownloadLocation();
|
||||
Intent intent = new Intent(getActivity(), DirPickerActivity.class);
|
||||
if (uniFile != null) {
|
||||
intent.putExtra(DirPickerActivity.KEY_FILE_URI, uniFile.getUri());
|
||||
}
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR);
|
||||
}
|
||||
|
||||
private void openDirPickerL() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
@@ -137,31 +105,20 @@ public class DownloadFragment extends PreferenceFragmentCompat implements
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
UniFile uniFile = UniFile.fromUri(getActivity(), data.getData());
|
||||
if (uniFile != null) {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_cant_get_download_location,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR_L: {
|
||||
if (resultCode == Activity.RESULT_OK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Uri treeUri = data.getData();
|
||||
requireActivity().getContentResolver().takePersistableUriPermission(
|
||||
treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
UniFile uniFile = UniFile.fromTreeUri(getActivity(), treeUri);
|
||||
if (uniFile != null) {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_cant_get_download_location,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
if (treeUri != null) {
|
||||
requireActivity().getContentResolver().takePersistableUriPermission(
|
||||
treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
UniFile uniFile = UniFile.fromTreeUri(getActivity(), treeUri);
|
||||
if (uniFile != null) {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_cant_get_download_location,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -399,11 +399,6 @@
|
||||
<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>
|
||||
|
||||
@@ -399,11 +399,6 @@
|
||||
<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>
|
||||
|
||||
@@ -398,11 +398,6 @@
|
||||
<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>
|
||||
|
||||
@@ -444,11 +444,6 @@
|
||||
<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>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<!-- ========== -->
|
||||
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<item name="android:navigationBarColor">@color/colorNavigationBar</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">@bool/lightNavigationBar</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
@@ -78,6 +78,8 @@
|
||||
|
||||
<style name="ThemeOverlay"/>
|
||||
<style name="ThemeOverlay.Black">
|
||||
<item name="android:navigationBarColor">@android:color/black</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
|
||||
<item name="android:colorEdgeEffect">?attr/colorEdgeEffect</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@android:color/black</item>
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SimpleMenuPreference
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:key="read_cache_size"
|
||||
android:title="@string/settings_advanced_read_cache_size"
|
||||
android:summary="%s"
|
||||
@@ -82,7 +81,6 @@
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<com.hippo.preference.ActivityPreference
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:key="custom_hosts"
|
||||
android:title="@string/settings_advanced_custom_hosts_title"
|
||||
android:summary="@string/settings_advanced_custom_hosts_summary"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
app:summaryOn="@string/settings_privacy_secure_summary"
|
||||
app:summaryOff="@string/settings_privacy_secure_summary"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
<!--
|
||||
<SwitchPreferenceCompat
|
||||
app:iconSpaceReserved="false"
|
||||
android:key="enable_analytics"
|
||||
@@ -29,5 +29,5 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:dialogMessage="@string/analytics_explain"
|
||||
app:dialogMessageHtml="true"
|
||||
app:dialogMessageLinkify="true"/>
|
||||
app:dialogMessageLinkify="true"/>-->
|
||||
</PreferenceScreen>
|
||||
Reference in new issue
Block a user