Migrate UConfig and MyTags to fragment
This commit is contained in:
17 files changed
+208
-158
No files matched your search
@@ -147,18 +147,6 @@
|
||||
android:label="@string/settings"
|
||||
android:theme="@style/AppTheme.Toolbar" />
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.UConfigActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:label="@string/u_config"
|
||||
android:theme="@style/AppTheme.Toolbar" />
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MyTagsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:label="@string/my_tags"
|
||||
android:theme="@style/AppTheme.Toolbar" />
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.shortcuts.ShortcutsActivity"
|
||||
android:excludeFromRecents="true"
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2019 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.preference;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class SignInRequiredPreference extends Preference implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private SettingsActivity mActivity;
|
||||
|
||||
public SignInRequiredPreference(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public SignInRequiredPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public SignInRequiredPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mActivity = (SettingsActivity) context;
|
||||
setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(getContext());
|
||||
HttpUrl e = HttpUrl.get(EhUrl.HOST_E);
|
||||
HttpUrl ex = HttpUrl.get(EhUrl.HOST_EX);
|
||||
|
||||
if (store.contains(e, EhCookieStore.KEY_IPD_MEMBER_ID) ||
|
||||
store.contains(e, EhCookieStore.KEY_IPD_PASS_HASH) ||
|
||||
store.contains(ex, EhCookieStore.KEY_IPD_MEMBER_ID) ||
|
||||
store.contains(ex, EhCookieStore.KEY_IPD_PASS_HASH)) {
|
||||
return false;
|
||||
} else {
|
||||
mActivity.showTip(R.string.error_please_login_first, BaseScene.LENGTH_SHORT);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.microsoft.appcenter.distribute.Distribute;
|
||||
|
||||
public class AboutFragment extends BaseSettingsFragment {
|
||||
public class AboutFragment extends BasePreferenceFragment {
|
||||
|
||||
private static final String KEY_AUTHOR = "author";
|
||||
//private static final String KEY_DONATE = "donate";
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.LogCat;
|
||||
@@ -50,7 +49,7 @@ import java.util.Arrays;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class AdvancedFragment extends BaseSettingsFragment {
|
||||
public class AdvancedFragment extends BasePreferenceFragment {
|
||||
|
||||
private static final int REQUEST_CODE_EXPORT = 1;
|
||||
private static final int REQUEST_CODE_IMPORT = 2;
|
||||
@@ -93,13 +92,13 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
startActivityForResult(intent, REQUEST_DUMP_LOGCAT);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
return true;
|
||||
} else if (KEY_CLEAR_MEMORY_CACHE.equals(key)) {
|
||||
((EhApplication) getActivity().getApplication()).clearMemoryCache();
|
||||
Runtime.getRuntime().gc();
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.settings_advanced_clear_memory_cache_done, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.settings_advanced_clear_memory_cache_done, BaseScene.LENGTH_SHORT);
|
||||
} else if (KEY_IMPORT_DATA.equals(key)) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
@@ -109,7 +108,7 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
startActivityForResult(intent, REQUEST_CODE_IMPORT);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
return true;
|
||||
} else if (KEY_EXPORT_DATA.equals(key)) {
|
||||
@@ -122,7 +121,7 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
startActivityForResult(intent, REQUEST_CODE_EXPORT);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -156,7 +155,7 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
if (alertDialog.isShowing()) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
((SettingsActivity) requireActivity()).showTip(
|
||||
showTip(
|
||||
(success)
|
||||
? GetText.getString(R.string.settings_advanced_export_data_to, uri.toString())
|
||||
: GetText.getString(R.string.settings_advanced_export_data_failed),
|
||||
@@ -164,7 +163,7 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
});
|
||||
}).start();
|
||||
} catch (Exception e) {
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.settings_advanced_export_data_failed, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.settings_advanced_export_data_failed, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,14 +190,14 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
if (null == error) {
|
||||
((SettingsActivity) requireActivity()).showTip(getString(R.string.settings_advanced_import_data_successfully), BaseScene.LENGTH_SHORT);
|
||||
showTip(getString(R.string.settings_advanced_import_data_successfully), BaseScene.LENGTH_SHORT);
|
||||
} else {
|
||||
((SettingsActivity) requireActivity()).showTip(error, BaseScene.LENGTH_SHORT);
|
||||
showTip(error, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
} catch (Exception e) {
|
||||
((SettingsActivity) requireActivity()).showTip(e.getLocalizedMessage(), BaseScene.LENGTH_SHORT);
|
||||
showTip(e.getLocalizedMessage(), BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,11 +275,11 @@ public class AdvancedFragment extends BaseSettingsFragment {
|
||||
if (!finished) {
|
||||
finished = LogCat.save(requireActivity().getContentResolver().openOutputStream(uri));
|
||||
}
|
||||
((SettingsActivity) requireActivity()).showTip(
|
||||
showTip(
|
||||
finished ? getString(R.string.settings_advanced_dump_logcat_to, uri.toString()) :
|
||||
getString(R.string.settings_advanced_dump_logcat_failed), BaseScene.LENGTH_SHORT);
|
||||
} catch (Exception e) {
|
||||
((SettingsActivity) requireActivity()).showTip(getString(R.string.settings_advanced_dump_logcat_failed), BaseScene.LENGTH_SHORT);
|
||||
showTip(getString(R.string.settings_advanced_dump_logcat_failed), BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
|
||||
public class BaseFragment extends Fragment {
|
||||
|
||||
public void setTitle(@StringRes int string) {
|
||||
requireActivity().setTitle(string);
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
((SettingsActivity) requireActivity()).showTip(getString(id), length);
|
||||
}
|
||||
|
||||
public void showTip(CharSequence message, int length) {
|
||||
((SettingsActivity) requireActivity()).showTip(message, length);
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -6,9 +6,10 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
import com.takisoft.preferencex.PreferenceFragmentCompat;
|
||||
|
||||
public class BaseSettingsFragment extends PreferenceFragmentCompat
|
||||
public class BasePreferenceFragment extends PreferenceFragmentCompat
|
||||
implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@@ -28,4 +29,12 @@ public class BaseSettingsFragment extends PreferenceFragmentCompat
|
||||
public void setTitle(@StringRes int string) {
|
||||
requireActivity().setTitle(string);
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
((SettingsActivity) requireActivity()).showTip(getString(id), length);
|
||||
}
|
||||
|
||||
public void showTip(CharSequence message, int length) {
|
||||
((SettingsActivity) requireActivity()).showTip(message, length);
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,11 @@ import androidx.preference.Preference;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class DownloadFragment extends BaseSettingsFragment {
|
||||
public class DownloadFragment extends BasePreferenceFragment {
|
||||
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
|
||||
|
||||
@@ -95,7 +94,7 @@ public class DownloadFragment extends BaseSettingsFragment {
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
showTip(R.string.error_cant_find_activity, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ public class DownloadFragment extends BaseSettingsFragment {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
((SettingsActivity) requireActivity()).showTip(R.string.settings_download_cant_get_download_location,
|
||||
showTip(R.string.settings_download_cant_get_download_location,
|
||||
BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhTagDatabase;
|
||||
|
||||
public class EhFragment extends BaseSettingsFragment {
|
||||
public class EhFragment extends BasePreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
|
||||
@@ -17,9 +17,7 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -41,7 +39,7 @@ import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FilterFragment extends Fragment {
|
||||
public class FilterFragment extends BaseFragment {
|
||||
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
@@ -452,7 +450,4 @@ public class FilterFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(@StringRes int string) {
|
||||
requireActivity().setTitle(string);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,8 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -33,7 +31,7 @@ import com.hippo.yorozuya.ViewUtils;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class HostsFragment extends Fragment
|
||||
public class HostsFragment extends BaseFragment
|
||||
implements View.OnClickListener {
|
||||
|
||||
private static final String DIALOG_TAG_ADD_HOST = AddHostDialogFragment.class.getName();
|
||||
@@ -84,8 +82,6 @@ public class HostsFragment extends Fragment
|
||||
|
||||
fab.setOnClickListener(this);
|
||||
|
||||
updateView(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -276,7 +272,4 @@ public class HostsFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(@StringRes int string) {
|
||||
requireActivity().setTitle(string);
|
||||
}
|
||||
}
|
||||
+29
-43
@@ -1,30 +1,16 @@
|
||||
/*
|
||||
* Copyright 2019 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;
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -37,14 +23,35 @@ import com.hippo.widget.ProgressView;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class MyTagsActivity extends ToolbarActivity {
|
||||
public class MyTagsFragment extends BaseFragment {
|
||||
|
||||
private WebView webView;
|
||||
private ProgressView progress;
|
||||
private String url;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Nullable
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.activity_webview, container, false);
|
||||
setTitle(R.string.my_tags);
|
||||
webView = view.findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.setWebViewClient(new MyTagsWebViewClient());
|
||||
webView.setWebChromeClient(new DialogWebChromeClient(requireContext()));
|
||||
progress = view.findViewById(R.id.progress);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
webView.loadUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
|
||||
@@ -56,38 +63,17 @@ public class MyTagsActivity extends ToolbarActivity {
|
||||
|
||||
// Copy cookies from okhttp cookie store to CookieManager
|
||||
url = EhUrl.getMyTagsUrl();
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(this);
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(requireContext());
|
||||
for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
|
||||
cookieManager.setCookie(url, cookie.toString());
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_webview);
|
||||
setTitle(R.string.my_tags);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
WebView webView = findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.setWebViewClient(new MyTagsWebViewClient());
|
||||
webView.setWebChromeClient(new DialogWebChromeClient(this));
|
||||
webView.loadUrl(url);
|
||||
progress = findViewById(R.id.progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private class MyTagsWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
// Never load other urls
|
||||
return !url.equals(MyTagsActivity.this.url);
|
||||
return !url.equals(MyTagsFragment.this.url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -14,7 +14,7 @@ import com.hippo.ehviewer.Settings;
|
||||
* Created by Mo10 on 2018/2/10.
|
||||
*/
|
||||
|
||||
public class PrivacyFragment extends BaseSettingsFragment {
|
||||
public class PrivacyFragment extends BasePreferenceFragment {
|
||||
private static final String KEY_PATTERN_PROTECTION = "pattern_protection";
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class ReadFragment extends BaseSettingsFragment {
|
||||
public class ReadFragment extends BasePreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
|
||||
@@ -9,9 +9,7 @@ import android.widget.CheckBox;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.biometric.BiometricManager;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -19,7 +17,7 @@ import com.hippo.widget.lockpattern.LockPatternUtils;
|
||||
import com.hippo.widget.lockpattern.LockPatternView;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class SetSecurityFragment extends Fragment implements View.OnClickListener {
|
||||
public class SetSecurityFragment extends BaseFragment implements View.OnClickListener {
|
||||
|
||||
@Nullable
|
||||
private LockPatternView mPatternView;
|
||||
@@ -82,8 +80,4 @@ public class SetSecurityFragment extends Fragment implements View.OnClickListene
|
||||
requireActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(@StringRes int string) {
|
||||
requireActivity().setTitle(string);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class SettingsFragment extends BaseSettingsFragment {
|
||||
public class SettingsFragment extends BasePreferenceFragment {
|
||||
@Override
|
||||
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.settings_headers);
|
||||
|
||||
+46
-55
@@ -1,49 +1,33 @@
|
||||
/*
|
||||
* Copyright 2018 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;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2018/2/9.
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.ehviewer.widget.DialogWebChromeClient;
|
||||
import com.hippo.widget.ProgressView;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class UConfigActivity extends ToolbarActivity {
|
||||
public class UConfigFragment extends BaseFragment {
|
||||
|
||||
private WebView webView;
|
||||
private ProgressView progress;
|
||||
@@ -51,9 +35,31 @@ public class UConfigActivity extends ToolbarActivity {
|
||||
private boolean loaded;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Nullable
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.activity_webview, container, false);
|
||||
setTitle(R.string.u_config);
|
||||
webView = view.findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.setWebViewClient(new UConfigWebViewClient());
|
||||
webView.setWebChromeClient(new DialogWebChromeClient(requireContext()));
|
||||
progress = view.findViewById(R.id.progress);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
webView.loadUrl(url);
|
||||
showTip(R.string.apply_tip, BaseScene.LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
@@ -64,22 +70,10 @@ public class UConfigActivity extends ToolbarActivity {
|
||||
|
||||
// Copy cookies from okhttp cookie store to CookieManager
|
||||
url = EhUrl.getUConfigUrl();
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(this);
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(requireContext());
|
||||
for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
|
||||
cookieManager.setCookie(url, cookie.toString());
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_webview);
|
||||
setTitle(R.string.u_config);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
webView = findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.setWebViewClient(new UConfigWebViewClient());
|
||||
webView.setWebChromeClient(new DialogWebChromeClient(this));
|
||||
webView.loadUrl(url);
|
||||
progress = findViewById(R.id.progress);
|
||||
|
||||
Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void apply() {
|
||||
@@ -91,26 +85,20 @@ public class UConfigActivity extends ToolbarActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.activity_u_config, menu);
|
||||
return true;
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.activity_u_config, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_apply:
|
||||
if (loaded) {
|
||||
apply();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
if (item.getItemId() == R.id.action_apply) {
|
||||
if (loaded) {
|
||||
apply();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private Cookie longLive(Cookie cookie) {
|
||||
@@ -124,8 +112,8 @@ public class UConfigActivity extends ToolbarActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
webView.destroy();
|
||||
|
||||
// Put cookies back to okhttp cookie store
|
||||
@@ -133,9 +121,12 @@ public class UConfigActivity extends ToolbarActivity {
|
||||
String cookiesString = cookieManager.getCookie(url);
|
||||
|
||||
if (cookiesString != null && !cookiesString.isEmpty()) {
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(this);
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(requireContext());
|
||||
HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
|
||||
HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);
|
||||
if (eUrl == null || exUrl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The cookies saved in the uconfig page should be shared between e and ex
|
||||
for (String header : cookiesString.split(";")) {
|
||||
@@ -38,18 +38,18 @@
|
||||
app:entryValues="@array/gallery_site_entry_values"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<com.hippo.ehviewer.preference.SignInRequiredActivityPreference
|
||||
<com.hippo.ehviewer.preference.SignInRequiredPreference
|
||||
android:key="u_config"
|
||||
android:summary="@string/settings_u_config_summary"
|
||||
android:title="@string/settings_u_config"
|
||||
app:activity="com.hippo.ehviewer.ui.UConfigActivity"
|
||||
android:fragment="com.hippo.ehviewer.ui.fragment.UConfigFragment"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<com.hippo.ehviewer.preference.SignInRequiredActivityPreference
|
||||
<com.hippo.ehviewer.preference.SignInRequiredPreference
|
||||
android:key="my_tags"
|
||||
android:summary="@string/settings_my_tags_summary"
|
||||
android:title="@string/settings_my_tags"
|
||||
app:activity="com.hippo.ehviewer.ui.MyTagsActivity"
|
||||
android:fragment="com.hippo.ehviewer.ui.fragment.MyTagsFragment"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<com.takisoft.preferencex.SimpleMenuPreference
|
||||
|
||||
Reference in new issue
Block a user