mirror of https://github.com/kurisufriend/Clover
Merge branch 'http_proxy_settings' of https://github.com/KOSBUM/Clover into KOSBUM-http_proxy_settings
commit
448abe033c
@ -0,0 +1,32 @@ |
||||
package org.floens.chan.core.net; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.InetSocketAddress; |
||||
import java.net.Proxy; |
||||
import java.net.URL; |
||||
import com.android.volley.toolbox.HurlStack; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
|
||||
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
|
||||
if (ChanSettings.proxyEnabled.get()) |
||||
{ |
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( |
||||
ChanSettings.proxyAddress.get(), |
||||
ChanSettings.proxyPort.get())); |
||||
return (HttpURLConnection) url.openConnection(proxy); |
||||
} |
||||
else |
||||
{ |
||||
return (HttpURLConnection) url.openConnection(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
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,74 @@ |
||||
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