Skip to content

Commit

Permalink
feat: button to switch auto connect
Browse files Browse the repository at this point in the history
  • Loading branch information
oldkingOK committed Jul 27, 2024
1 parent ac6b99a commit 7cb53f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/cx/myth/zjuconnect/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

import androidx.activity.result.ActivityResultLauncher;
Expand Down Expand Up @@ -161,10 +163,16 @@ protected void onCreate(Bundle savedInstanceState) {
}
});

if (sharedPreferences.getBoolean("hasConnected", false)) {
CheckBox checkBox = findViewById(R.id.autoConnectCheckBox);
checkBox.setChecked(sharedPreferences.getBoolean("checked", true));
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("checked", isChecked);
editor.apply();
});
if (checkBox.isChecked() && sharedPreferences.getBoolean("hasConnected", false)) {
binding.fab.callOnClick();
}

}

private void startVpnService() {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/fragment_first.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
android:hint="@string/input_password"
android:inputType="textPassword"
android:textColorHint="@color/black" />

<CheckBox
android:id="@+id/autoConnectCheckBox"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="@string/auto_connect" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="about_fragment_label">关于</string>
<string name="icon">图标</string>
<string name="connected">已连接</string>
<string name="auto_connect">自动连接</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<string name="about_fragment_label">About</string>
<string name="icon">Icon</string>
<string name="connected">Connected</string>
<string name="auto_connect">Auto Connect</string>
</resources>

0 comments on commit 7cb53f5

Please sign in to comment.