-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsActivity.java
More file actions
203 lines (171 loc) · 9.08 KB
/
OptionsActivity.java
File metadata and controls
203 lines (171 loc) · 9.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package io.github.iso53.nothingcompass;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList;
import java.util.List;
import io.github.iso53.nothingcompass.model.OptionItem;
import io.github.iso53.nothingcompass.preference.PreferenceConstants;
import io.github.iso53.nothingcompass.view.OptionsAdapter;
public class OptionsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Apply theme before super.onCreate
SharedPreferences themePrefs = PreferenceManager.getDefaultSharedPreferences(this);
int themeMode = themePrefs.getInt(PreferenceConstants.THEME,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
AppCompatDelegate.setDefaultNightMode(themeMode);
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_options);
setupToolbar();
setupRecyclerView();
}
private void setupToolbar() {
// Add back button
findViewById(R.id.optionsToolbar).setOnClickListener(v -> finish());
((androidx.appcompat.widget.Toolbar) findViewById(R.id.optionsToolbar))
.setNavigationOnClickListener(v -> finish());
// Change the font of the title
CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapseToolbar);
Typeface typeface = ResourcesCompat.getFont(this, R.font.ntype82headline);
collapsingToolbar.setExpandedTitleTypeface(typeface);
collapsingToolbar.setCollapsedTitleTypeface(typeface);
}
private void setupRecyclerView() {
RecyclerView recyclerView = findViewById(R.id.optionsRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
List<OptionItem> items = new ArrayList<>();
// Category: Preferences
items.add(new OptionItem(getString(R.string.category_preferences)));
items.add(new OptionItem(getString(R.string.item_theme), null, R.drawable.ic_settings,
v -> showThemeSelectionDialog()));
items.add(new OptionItem(getString(R.string.item_haptic_feedback), null,
R.drawable.ic_vibration, v -> showHapticFeedbackSelectionDialog()));
// Category: App
items.add(new OptionItem(getString(R.string.category_app)));
items.add(new OptionItem(getString(R.string.item_version_update), null,
R.drawable.ic_version_update, v -> openPlayStore()));
items.add(new OptionItem(getString(R.string.item_about), null, R.drawable.ic_about,
v -> startActivity(new Intent(this, AboutActivity.class))));
items.add(new OptionItem(getString(R.string.item_author), null, R.drawable.ic_person,
v -> openUrl("https://github.com/iso53")));
items.add(new OptionItem(getString(R.string.item_source_code), null, R.drawable.ic_code,
v -> openUrl("https://github.com/iso53/Nothing-Compass")));
// Category: Support
items.add(new OptionItem(getString(R.string.category_support)));
items.add(new OptionItem(getString(R.string.item_license), null, R.drawable.ic_license,
v -> openUrl("https://github.com/iso53/Nothing-Compass/blob/main/LICENSE")));
items.add(new OptionItem(getString(R.string.item_third_party_licenses), null,
R.drawable.ic_verified, v -> startActivity(new Intent(this,
OssLicensesMenuActivity.class))));
items.add(new OptionItem(getString(R.string.item_manage_permission), null,
R.drawable.ic_permission, v -> openAppSettings()));
items.add(new OptionItem(getString(R.string.item_help_feedback), null, R.drawable.ic_help
, v -> sendFeedbackEmail()));
items.add(new OptionItem(getString(R.string.item_rate_app), null, R.drawable.ic_rate,
v -> openPlayStore()));
OptionsAdapter adapter = new OptionsAdapter(items);
recyclerView.setAdapter(adapter);
}
private void showThemeSelectionDialog() {
String[] themes = {getString(R.string.theme_light), getString(R.string.theme_dark),
getString(R.string.theme_system)};
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int currentTheme = prefs.getInt(PreferenceConstants.THEME,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
int checkedItem = 2; // Default to System
if (currentTheme == AppCompatDelegate.MODE_NIGHT_NO)
checkedItem = 0;
else if (currentTheme == AppCompatDelegate.MODE_NIGHT_YES)
checkedItem = 1;
new MaterialAlertDialogBuilder(this).setTitle(R.string.item_theme)
.setSingleChoiceItems(themes, checkedItem, (dialog, which) -> {
int mode;
switch (which) {
case 0:
mode = AppCompatDelegate.MODE_NIGHT_NO;
break;
case 1:
mode = AppCompatDelegate.MODE_NIGHT_YES;
break;
default:
mode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
break;
}
prefs.edit().putInt(PreferenceConstants.THEME, mode).apply();
AppCompatDelegate.setDefaultNightMode(mode);
dialog.dismiss();
}).show();
}
private void showHapticFeedbackSelectionDialog() {
String[] options = {getString(R.string.haptic_feedback_on),
getString(R.string.haptic_feedback_off)};
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean currentHaptic = prefs.getBoolean(PreferenceConstants.HAPTIC_FEEDBACK, true);
int checkedItem = currentHaptic ? 0 : 1;
new MaterialAlertDialogBuilder(this).setTitle(R.string.item_haptic_feedback)
.setSingleChoiceItems(options, checkedItem, (dialog, which) -> {
boolean enabled = (which == 0);
prefs.edit().putBoolean(PreferenceConstants.HAPTIC_FEEDBACK, enabled).apply();
dialog.dismiss();
}).show();
}
private void openPlayStore() {
String packageName = getPackageName();
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + packageName)));
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google" +
".com/store/apps/details?id=" + packageName)));
}
}
private void openUrl(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
private void openAppSettings() {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
private void sendFeedbackEmail() {
String feedbackEmail = "ihsansimsek5335@gmail.com";
String appVersion = "Unknown";
try {
appVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (Exception ignored) {
}
String deviceInfo = "\n\n\n------------------------------" + "\nDevice Diagnostics " +
"(Please do not delete):" + "\nApp Version: " + appVersion + "\nAndroid Version: "
+ android.os.Build.VERSION.RELEASE + " (SDK " + android.os.Build.VERSION.SDK_INT + ")"
+ "\nManufacturer: " + android.os.Build.MANUFACTURER + "\nModel: "
+ android.os.Build.MODEL
+ "\nProduct: " + android.os.Build.PRODUCT;
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{feedbackEmail});
intent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support - Nothing Compass");
intent.putExtra(Intent.EXTRA_TEXT, deviceInfo);
try {
startActivity(Intent.createChooser(intent, "Send Feedback"));
} catch (ActivityNotFoundException e) {
// Fallback to GitHub issues if no email app found
openUrl("https://github.com/iso53/Nothing-Compass/issues");
}
}
}