mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-09 23:50:02 +00:00
Add basic switch for day/night mode
This commit is contained in:
parent
967345e1c3
commit
5d93041ee3
6 changed files with 61 additions and 7 deletions
|
@ -21,6 +21,7 @@ import com.m2049r.xmrwallet.service.MoneroHandlerThread;
|
|||
import com.m2049r.xmrwallet.service.PrefService;
|
||||
import com.m2049r.xmrwallet.service.TxService;
|
||||
import com.m2049r.xmrwallet.util.Constants;
|
||||
import com.m2049r.xmrwallet.util.NightmodeHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -37,6 +38,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
NightmodeHelper.getAndSetPreferredNightmode(this);
|
||||
File walletFile = new File(getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
||||
new PrefService(this);
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
|
@ -15,6 +17,8 @@ import com.m2049r.xmrwallet.R;
|
|||
import com.m2049r.xmrwallet.model.Wallet;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import com.m2049r.xmrwallet.service.BlockchainService;
|
||||
import com.m2049r.xmrwallet.util.DayNightMode;
|
||||
import com.m2049r.xmrwallet.util.NightmodeHelper;
|
||||
|
||||
public class SettingsFragment extends Fragment {
|
||||
|
||||
|
@ -31,7 +35,10 @@ public class SettingsFragment extends Fragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
|
||||
TextView walletInfoTextView = view.findViewById(R.id.wallet_info_textview);
|
||||
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Seed: " + wallet.getSeed("")+"\n\n");
|
||||
stringBuilder.append("Private view-key: " + wallet.getSecretViewKey()+"\n\n");
|
||||
|
@ -39,5 +46,14 @@ public class SettingsFragment extends Fragment {
|
|||
stringBuilder.append("Wallet height: " + wallet.getBlockChainHeight() + "\n\n");
|
||||
stringBuilder.append("Daemon height: " + BlockchainService.getInstance().getDaemonHeight() + "\n\n");
|
||||
walletInfoTextView.setText(stringBuilder.toString());
|
||||
|
||||
nightModeSwitch.setChecked(NightmodeHelper.getPreferredNightmode(getContext()) == DayNightMode.NIGHT);
|
||||
nightModeSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
if(b) {
|
||||
NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.NIGHT);
|
||||
} else {
|
||||
NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.DAY);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -26,16 +26,21 @@ import com.m2049r.xmrwallet.R;
|
|||
|
||||
public class NightmodeHelper {
|
||||
public static DayNightMode getPreferredNightmode(Context context) {
|
||||
return DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context)
|
||||
DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(context.getString(R.string.preferred_nightmode), "UNKNOWN"));
|
||||
if(mode == DayNightMode.UNKNOWN) {
|
||||
mode = DayNightMode.NIGHT;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static void setPreferredNightmode(Context context) {
|
||||
final DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context)
|
||||
public static void getAndSetPreferredNightmode(Context context) {
|
||||
DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(context.getString(R.string.preferred_nightmode), "UNKNOWN"));
|
||||
if (mode == DayNightMode.UNKNOWN)
|
||||
setAndSavePreferredNightmode(context, DayNightMode.AUTO);
|
||||
else
|
||||
if(mode == DayNightMode.UNKNOWN) {
|
||||
mode = DayNightMode.NIGHT;
|
||||
}
|
||||
|
||||
setNightMode(mode);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,4 +24,13 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/day_night_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_marginStart="24dp"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
11
app/src/main/res/values-night-v23/styles.xml
Normal file
11
app/src/main/res/values-night-v23/styles.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.DayNight">
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="materialCardViewStyle">@style/AppCard</item>
|
||||
<item name="materialButtonStyle">@style/AppButton</item>
|
||||
</style>
|
||||
</resources>
|
11
app/src/main/res/values-v23/styles.xml
Normal file
11
app/src/main/res/values-v23/styles.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.DayNight">
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="materialCardViewStyle">@style/AppCard</item>
|
||||
<item name="materialButtonStyle">@style/AppButton</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in a new issue