ConfigAddActivity: Add an standalone config-creating activity
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
e9de916d69
commit
61d6b89bbe
@ -19,6 +19,9 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".ConfigAddActivity"
|
||||||
|
android:label="@string/edit_activity_title" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
android:label="@string/settings" />
|
android:label="@string/settings" />
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.wireguard.android;
|
||||||
|
|
||||||
|
import android.app.FragmentManager;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standalone activity for creating configurations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ConfigAddActivity extends BaseConfigActivity {
|
||||||
|
@Override
|
||||||
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.config_add_activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCurrentConfigChanged(final Config config) {
|
||||||
|
// This is the result of ConfigEditFragment signalling that a configuration was created.
|
||||||
|
if (config != null)
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onServiceAvailable() {
|
||||||
|
super.onServiceAvailable();
|
||||||
|
final FragmentManager fm = getFragmentManager();
|
||||||
|
if (fm.findFragmentById(R.id.master_fragment) == null) {
|
||||||
|
final FragmentTransaction transaction = fm.beginTransaction();
|
||||||
|
transaction.add(R.id.master_fragment, new ConfigEditFragment());
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.wireguard.android.databinding.ConfigEditFragmentBinding;
|
import com.wireguard.android.databinding.ConfigEditFragmentBinding;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
@ -73,7 +74,15 @@ public class ConfigEditFragment extends BaseConfigFragment {
|
|||||||
|
|
||||||
private void saveConfig() {
|
private void saveConfig() {
|
||||||
// FIXME: validate input
|
// FIXME: validate input
|
||||||
VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);
|
try {
|
||||||
|
if (getCurrentConfig() != null)
|
||||||
|
VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);
|
||||||
|
else
|
||||||
|
VpnService.getInstance().add(localConfig);
|
||||||
|
} catch (final IllegalStateException e) {
|
||||||
|
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Hide the keyboard; it rarely goes away on its own.
|
// Hide the keyboard; it rarely goes away on its own.
|
||||||
final BaseConfigActivity activity = (BaseConfigActivity) getActivity();
|
final BaseConfigActivity activity = (BaseConfigActivity) getActivity();
|
||||||
final View focusedView = activity.getCurrentFocus();
|
final View focusedView = activity.getCurrentFocus();
|
||||||
@ -83,7 +92,7 @@ public class ConfigEditFragment extends BaseConfigFragment {
|
|||||||
inputManager.hideSoftInputFromWindow(focusedView.getWindowToken(),
|
inputManager.hideSoftInputFromWindow(focusedView.getWindowToken(),
|
||||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||||
}
|
}
|
||||||
// Tell the activity to go back to the detail view.
|
// Tell the activity to finish itself or go back to the detail view.
|
||||||
activity.setCurrentConfig(localConfig);
|
activity.setCurrentConfig(localConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
app/src/main/res/layout/config_add_activity.xml
Normal file
5
app/src/main/res/layout/config_add_activity.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/master_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
@ -6,6 +6,7 @@
|
|||||||
<string name="disconnected">Disconnected</string>
|
<string name="disconnected">Disconnected</string>
|
||||||
<string name="dns_servers">DNS servers</string>
|
<string name="dns_servers">DNS servers</string>
|
||||||
<string name="edit">Edit</string>
|
<string name="edit">Edit</string>
|
||||||
|
<string name="edit_activity_title">Add WireGuard Configuration</string>
|
||||||
<string name="generate">Generate</string>
|
<string name="generate">Generate</string>
|
||||||
<string name="hint_automatic">(auto)</string>
|
<string name="hint_automatic">(auto)</string>
|
||||||
<string name="hint_generated">(generated)</string>
|
<string name="hint_generated">(generated)</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user