1
1
package ca .pkay .rcloneexplorer ;
2
2
3
3
import android .app .ActivityManager ;
4
+ import android .content .Intent ;
4
5
import android .content .SharedPreferences ;
5
6
import android .graphics .Bitmap ;
6
7
import android .graphics .BitmapFactory ;
7
8
import android .os .Bundle ;
8
9
import android .preference .PreferenceManager ;
10
+ import android .support .design .widget .Snackbar ;
9
11
import android .support .v7 .app .ActionBar ;
10
12
import android .support .v7 .app .AppCompatActivity ;
11
13
import android .support .v7 .widget .Toolbar ;
12
14
import android .view .View ;
13
15
import android .widget .CompoundButton ;
14
16
import android .widget .Switch ;
15
- import android .widget .Toast ;
17
+ import android .widget .TextView ;
16
18
17
19
import ca .pkay .rcloneexplorer .Dialogs .ColorPickerDialog ;
18
- import es .dmoral .toasty .Toasty ;
19
20
20
21
public class SettingsActivity extends AppCompatActivity {
21
22
@@ -25,6 +26,7 @@ public class SettingsActivity extends AppCompatActivity {
25
26
private View accentColorPreview ;
26
27
private Switch darkThemeSwitch ;
27
28
private View darkThemeElement ;
29
+ private View notificationsElement ;
28
30
private Switch useLogsSwitch ;
29
31
private View useLogsElement ;
30
32
private boolean isDarkTheme ;
@@ -79,6 +81,7 @@ private void getViews() {
79
81
accentColorPreview = findViewById (R .id .accent_color_preview );
80
82
darkThemeSwitch = findViewById (R .id .dark_theme_switch );
81
83
darkThemeElement = findViewById (R .id .dark_theme );
84
+ notificationsElement = findViewById (R .id .notifications );
82
85
useLogsSwitch = findViewById (R .id .use_logs_switch );
83
86
useLogsElement = findViewById (R .id .use_logs );
84
87
}
@@ -131,6 +134,12 @@ public void onClick(View v) {
131
134
}
132
135
}
133
136
});
137
+ notificationsElement .setOnClickListener (new View .OnClickListener () {
138
+ @ Override
139
+ public void onClick (View v ) {
140
+ onNotificationsClicked ();
141
+ }
142
+ });
134
143
useLogsSwitch .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
135
144
@ Override
136
145
public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
@@ -186,7 +195,7 @@ private void onPrimaryColorSelected(int color) {
186
195
editor .apply ();
187
196
188
197
primaryColorPreview .getBackground ().setTint (color );
189
- Toasty . info ( this , getString ( R . string . restart_required ), Toast . LENGTH_SHORT , true ). show ();
198
+ showSnackBar ();
190
199
}
191
200
192
201
private void onAccentColorSelected (int color ) {
@@ -196,7 +205,7 @@ private void onAccentColorSelected(int color) {
196
205
editor .apply ();
197
206
198
207
accentColorPreview .getBackground ().setTint (color );
199
- Toasty . info ( this , getString ( R . string . restart_required ), Toast . LENGTH_SHORT , true ). show ();
208
+ showSnackBar ();
200
209
}
201
210
202
211
private void onDarkThemeClicked (boolean isChecked ) {
@@ -205,7 +214,21 @@ private void onDarkThemeClicked(boolean isChecked) {
205
214
editor .putBoolean (getString (R .string .pref_key_dark_theme ), isChecked );
206
215
editor .apply ();
207
216
208
- Toasty .info (this , getString (R .string .restart_required ), Toast .LENGTH_SHORT , true ).show ();
217
+ showSnackBar ();
218
+ }
219
+
220
+ private void onNotificationsClicked () {
221
+ Intent intent = new Intent ();
222
+ intent .setAction ("android.settings.APP_NOTIFICATION_SETTINGS" );
223
+
224
+ //for Android 5-7
225
+ intent .putExtra ("app_package" , getPackageName ());
226
+ intent .putExtra ("app_uid" , getApplicationInfo ().uid );
227
+
228
+ // for Android O
229
+ intent .putExtra ("android.provider.extra.APP_PACKAGE" , getPackageName ());
230
+
231
+ startActivity (intent );
209
232
}
210
233
211
234
private void onUseLogsClicked (boolean isChecked ) {
@@ -214,4 +237,27 @@ private void onUseLogsClicked(boolean isChecked) {
214
237
editor .putBoolean (getString (R .string .pref_key_logs ), isChecked );
215
238
editor .apply ();
216
239
}
240
+
241
+ private void showSnackBar () {
242
+ Snackbar snackbar = Snackbar .make (findViewById (R .id .cl_activity_settings ), R .string .restart_required , Snackbar .LENGTH_LONG );
243
+ if (isDarkTheme ) {
244
+ snackbar .getView ().setBackgroundColor (getResources ().getColor (R .color .white ));
245
+ TextView tv = snackbar .getView ().findViewById (android .support .design .R .id .snackbar_text );
246
+ tv .setTextColor (getResources ().getColor (android .R .color .black ));
247
+ }
248
+ snackbar .setAction ("Restart" , new View .OnClickListener () {
249
+ @ Override
250
+ public void onClick (View v ) {
251
+ restartApp ();
252
+ }
253
+ });
254
+ snackbar .show ();
255
+ }
256
+
257
+ private void restartApp () {
258
+ Intent intent = new Intent (this , MainActivity .class );
259
+ startActivity (intent );
260
+ finish ();
261
+ Runtime .getRuntime ().exit (0 );
262
+ }
217
263
}
0 commit comments