Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/src/main/java/org/fptn/vpn/services/CustomVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
} else if (ACTION_DISCONNECT.equals(intent.getAction())) {
Log.i(TAG, "onStartCommand: disconnect!");
/* if we need disconnect */
// todo: move to settings option
fptnServerRepository.resetSelected();
if (SharedPrefUtils.getResetSelectedServerEnabled(this)) {
fptnServerRepository.resetSelected();
}
// stop running threads
disconnect();
} else if (ACTION_CONNECT.equals(intent.getAction())) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/fptn/vpn/utils/SharedPrefUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ public static void saveDelayBetweenReconnect(Context context, int delayInSeconds
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.APPLICATION_SHARED_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferences.edit().putInt(Constants.RECONNECT_DELAY_BETWEEN_SHARED_PREF_KEY, delayInSeconds).apply();
}

public static boolean getResetSelectedServerEnabled(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.APPLICATION_SHARED_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferences.getBoolean(Constants.RESET_SELECTED_SERVER_PREF_KEY, true);
}

public static void saveResetSelectedServerEnabled(Context context, boolean enabled) {
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.APPLICATION_SHARED_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferences.edit().putBoolean(Constants.RESET_SELECTED_SERVER_PREF_KEY, enabled).apply();
}
}
13 changes: 9 additions & 4 deletions app/src/main/java/org/fptn/vpn/views/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.textfield.TextInputEditText;

import org.fptn.vpn.R;
import org.fptn.vpn.services.tile.FptnTileService;
import org.fptn.vpn.utils.PermissionsUtils;
import org.fptn.vpn.utils.SharedPrefUtils;
import org.fptn.vpn.viewmodel.FptnServerViewModel;
import org.fptn.vpn.views.adapter.FptnServerAdapter;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.textfield.TextInputEditText;

import java.util.Optional;
import java.util.concurrent.Executors;

import lombok.Getter;

Expand Down Expand Up @@ -401,10 +400,16 @@ public void onStopTrackingTouch(SeekBar seekBar) {
seekBarDelayBetween.setProgress(0);
seekBarDelayBetween.setProgress(delayBetweenReconnect - 1);


/* Reset selected server on disconnect */
SwitchCompat resetServerAfterDisconnectSwitch = dialogView.findViewById(R.id.reset_selected_server_after_disconnect_switch);
resetServerAfterDisconnectSwitch.setChecked(SharedPrefUtils.getResetSelectedServerEnabled(this));

builder.setPositiveButton(getString(R.string.save_button), (dialog, which) -> {
Log.d(TAG, "experimentalFeaturesDialog: save");
SharedPrefUtils.saveReconnectOnChangeNetworkTypeEnabled(this, switchNetworkType.isChecked());
SharedPrefUtils.saveReconnectOnChangeIPEnabled(this, switchIPAddress.isChecked());
SharedPrefUtils.saveResetSelectedServerEnabled(this, resetServerAfterDisconnectSwitch.isChecked());

int attemptsCountProgress = seekBarAttemptsCount.getProgress();
if (attemptsCountProgress == 3) {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/experimental_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/reset_selected_server_after_disconnect_switch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/reset_selected_server_after_disconnect_label"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>

</LinearLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ https://play.google.com/store/apps/details?id=org.fptn.vpn
<string name="tile_already_added">Плитка быстрых настроек была добавлена ранее</string>
<string name="tile_added_successfully">Плитка быстрых настроек добавлена</string>
<string name="tile_addition_failed">Плитка быстрых настроек не добавлена!</string>
<string name="reset_selected_server_after_disconnect_label">Сброс выбранного сервера после отключения?</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,6 @@ https://play.google.com/store/apps/details?id=org.fptn.vpn
<string name="tile_already_added">Tile already added</string>
<string name="tile_added_successfully">Tile added successfully</string>
<string name="tile_addition_failed">Tile addition failed!</string>
<string name="reset_selected_server_after_disconnect_label">Reset selected server after disconnect?</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object Constants {

// Shares preferences constants
const val CURRENT_SNI_SHARED_PREF_KEY: String = "CURRENT_SNI"
const val AUTO_SNI_ENABLED_PREF_KEY: String = "AUTO_SNI_ENABLED"

const val RESET_SELECTED_SERVER_PREF_KEY: String = "RESET_SELECTED_SERVER_PREF_KEY"
const val APPLICATION_SHARED_PREFERENCES = "fptnvpn-shared-preferences"
const val PERMISSIONS_REQUESTED_SHARED_PREF_KEY: String = "permissions_requested_previously"
const val RECONNECT_ON_CHANGE_IP_ENABLED_SHARED_PREF_KEY: String = "RECONNECT_ON_CHANGE_IP_ENABLED"
Expand Down