mirror of https://github.com/kurisufriend/Clover
commit
0e98dd0f4b
@ -0,0 +1,44 @@ |
||||
/* |
||||
* 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.core.net; |
||||
|
||||
import com.android.volley.toolbox.HurlStack; |
||||
|
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.Proxy; |
||||
import java.net.URL; |
||||
|
||||
public class ProxiedHurlStack extends HurlStack { |
||||
public ProxiedHurlStack(String userAgent) { |
||||
super(userAgent, null); |
||||
} |
||||
|
||||
@Override |
||||
protected HttpURLConnection createConnection(URL url) throws IOException { |
||||
// Start the connection by specifying a proxy server
|
||||
Proxy proxy = ChanSettings.getProxy(); |
||||
if (proxy != null) { |
||||
return (HttpURLConnection) url.openConnection(proxy); |
||||
} else { |
||||
return (HttpURLConnection) url.openConnection(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
/* |
||||
* 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.core.settings; |
||||
|
||||
import android.content.SharedPreferences; |
||||
|
||||
/** |
||||
* Created by Zetsubou on 02.07.2015 |
||||
*/ |
||||
public class IntegerSetting extends Setting<Integer> { |
||||
private boolean hasCached = false; |
||||
private Integer cached; |
||||
|
||||
public IntegerSetting(SharedPreferences sharedPreferences, String key, Integer def) { |
||||
super(sharedPreferences, key, def); |
||||
} |
||||
|
||||
public IntegerSetting(SharedPreferences sharedPreferences, String key, Integer def, SettingCallback<Integer> callback) { |
||||
super(sharedPreferences, key, def, callback); |
||||
} |
||||
|
||||
@Override |
||||
public Integer get() { |
||||
if (hasCached) { |
||||
return cached; |
||||
} else { |
||||
cached = sharedPreferences.getInt(key, def); |
||||
hasCached = true; |
||||
return cached; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void set(Integer value) { |
||||
if (!value.equals(get())) { |
||||
sharedPreferences.edit().putInt(key, value).apply(); |
||||
cached = value; |
||||
onValueChanged(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@ |
||||
/* |
||||
* 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.settings; |
||||
|
||||
import android.app.AlertDialog; |
||||
import android.content.DialogInterface; |
||||
import android.text.InputType; |
||||
import android.view.View; |
||||
import android.view.WindowManager; |
||||
import android.view.inputmethod.EditorInfo; |
||||
import android.widget.EditText; |
||||
import android.widget.LinearLayout; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.settings.Setting; |
||||
|
||||
import static org.floens.chan.utils.AndroidUtils.dp; |
||||
|
||||
/** |
||||
* Created by Zetsubou on 02.07.2015 |
||||
*/ |
||||
public class IntegerSettingView extends SettingView implements View.OnClickListener { |
||||
private final Setting<Integer> setting; |
||||
private final String dialogTitle; |
||||
|
||||
public IntegerSettingView(SettingsController settingsController, Setting<Integer> setting, String name, String dialogTitle) { |
||||
super(settingsController, name); |
||||
this.setting = setting; |
||||
this.dialogTitle = dialogTitle; |
||||
} |
||||
|
||||
@Override |
||||
public void setView(View view) { |
||||
super.setView(view); |
||||
view.setOnClickListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public String getBottomDescription() { |
||||
return setting.get() != null ? setting.get().toString() : null; |
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View v) { |
||||
LinearLayout container = new LinearLayout(v.getContext()); |
||||
container.setPadding(dp(24), dp(8), dp(24), 0); |
||||
|
||||
final EditText editText = new EditText(v.getContext()); |
||||
editText.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); |
||||
editText.setText(setting.get().toString()); |
||||
editText.setInputType(InputType.TYPE_CLASS_NUMBER); |
||||
editText.setSingleLine(true); |
||||
|
||||
container.addView(editText, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(v.getContext()) |
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
||||
@Override |
||||
public void onClick(DialogInterface d, int which) { |
||||
try { |
||||
setting.set(Integer.parseInt(editText.getText().toString())); |
||||
} catch (Exception e) { |
||||
setting.set(setting.getDefault()); |
||||
} |
||||
|
||||
settingsController.onPreferenceChange(IntegerSettingView.this); |
||||
} |
||||
}) |
||||
.setNegativeButton(R.string.cancel, null) |
||||
.setTitle(dialogTitle) |
||||
.setView(container) |
||||
.create(); |
||||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); |
||||
dialog.show(); |
||||
} |
||||
} |
Loading…
Reference in new issue