|
1 | 1 | package com.james.status.activities; |
2 | 2 |
|
3 | | -import android.content.Intent; |
4 | | -import android.graphics.drawable.ColorDrawable; |
| 3 | +import android.content.DialogInterface; |
5 | 4 | import android.os.Bundle; |
6 | | -import android.support.annotation.NonNull; |
7 | 5 | import android.support.annotation.Nullable; |
8 | 6 | import android.support.v7.app.AppCompatActivity; |
9 | | -import android.support.v7.widget.GridLayoutManager; |
10 | | -import android.support.v7.widget.RecyclerView; |
11 | | -import android.support.v7.widget.SwitchCompat; |
12 | | -import android.support.v7.widget.Toolbar; |
13 | | -import android.view.MenuItem; |
14 | | -import android.view.View; |
15 | | -import android.widget.CompoundButton; |
16 | | -import android.widget.ImageView; |
17 | 7 |
|
18 | | -import com.afollestad.async.Action; |
19 | | -import com.james.status.R; |
20 | | -import com.james.status.adapters.ActivityAdapter; |
21 | | -import com.james.status.data.AppData; |
22 | | -import com.james.status.data.PreferenceData; |
23 | | -import com.james.status.dialogs.ColorPickerDialog; |
24 | | -import com.james.status.dialogs.PreferenceDialog; |
25 | | -import com.james.status.utils.ColorUtils; |
| 8 | +import com.james.status.data.AppPreferenceData; |
| 9 | +import com.james.status.dialogs.preference.AppPreferenceDialog; |
26 | 10 |
|
27 | 11 | public class AppSettingActivity extends AppCompatActivity { |
28 | 12 |
|
29 | | - public final static String EXTRA_APP = "com.james.status.EXTRA_APP"; |
30 | | - public final static String EXTRA_ACTIVITY = "com.james.status.EXTRA_ACTIVITY"; |
31 | | - |
32 | | - private AppData app; |
33 | | - private AppData.ActivityData activity; |
34 | | - private ImageView colorView; |
35 | | - |
36 | | - private ActivityAdapter adapter; |
| 13 | + public final static String EXTRA_COMPONENT = "com.james.status.EXTRA_COMPONENT"; |
37 | 14 |
|
38 | 15 | @Override |
39 | 16 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
40 | 17 | super.onCreate(savedInstanceState); |
41 | | - setContentView(R.layout.activity_app_settings); |
42 | | - |
43 | | - Intent intent = getIntent(); |
44 | | - app = intent.getParcelableExtra(EXTRA_APP); |
45 | | - |
46 | | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
47 | | - final RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler); |
48 | | - colorView = (ImageView) findViewById(R.id.colorView); |
49 | | - SwitchCompat fullscreenSwitch = (SwitchCompat) findViewById(R.id.fullscreenSwitch); |
50 | | - SwitchCompat notificationSwitch = (SwitchCompat) findViewById(R.id.notificationSwitch); |
51 | | - |
52 | | - toolbar.setTitle(app.label); |
53 | | - |
54 | | - setSupportActionBar(toolbar); |
55 | | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
56 | | - |
57 | | - findViewById(R.id.color).setOnClickListener(new View.OnClickListener() { |
| 18 | + AppPreferenceDialog dialog = new AppPreferenceDialog(this, new AppPreferenceData(this, getIntent().getStringExtra(EXTRA_COMPONENT))); |
| 19 | + dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
58 | 20 | @Override |
59 | | - public void onClick(View v) { |
60 | | - new Action<Integer>() { |
61 | | - @NonNull |
62 | | - @Override |
63 | | - public String id() { |
64 | | - return "activityColorDialog"; |
65 | | - } |
66 | | - |
67 | | - @Nullable |
68 | | - @Override |
69 | | - protected Integer run() throws InterruptedException { |
70 | | - return ColorUtils.getPrimaryColor(AppSettingActivity.this, app.getComponentName()); |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - protected void done(@Nullable Integer result) { |
75 | | - ColorPickerDialog dialog = new ColorPickerDialog(AppSettingActivity.this).withAlpha((Boolean) PreferenceData.STATUS_TRANSPARENT_MODE.getValue(AppSettingActivity.this)); |
76 | | - dialog.setPreference(app.getIntegerPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR)); |
77 | | - dialog.setDefaultPreference(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this)); |
78 | | - dialog.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() { |
79 | | - @Override |
80 | | - public void onPreference(PreferenceDialog dialog, Integer preference) { |
81 | | - app.putPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR, preference); |
82 | | - colorView.setImageDrawable(new ColorDrawable(preference)); |
83 | | - adapter.notifyDataSetChanged(); |
84 | | - } |
85 | | - |
86 | | - @Override |
87 | | - public void onCancel(PreferenceDialog dialog) { |
88 | | - } |
89 | | - }); |
90 | | - dialog.show(); |
91 | | - } |
92 | | - }.execute(); |
93 | | - } |
94 | | - }); |
95 | | - |
96 | | - Integer color = app.getIntegerPreference(this, AppData.PreferenceIdentifier.COLOR); |
97 | | - if (color != null) { |
98 | | - colorView.setImageDrawable(new ColorDrawable(color)); |
99 | | - } else { |
100 | | - new Action<Integer>() { |
101 | | - @NonNull |
102 | | - @Override |
103 | | - public String id() { |
104 | | - return "activityColor"; |
105 | | - } |
106 | | - |
107 | | - @Nullable |
108 | | - @Override |
109 | | - protected Integer run() throws InterruptedException { |
110 | | - return ColorUtils.getPrimaryColor(AppSettingActivity.this, app.getComponentName()); |
111 | | - } |
112 | | - |
113 | | - @Override |
114 | | - protected void done(@Nullable Integer result) { |
115 | | - colorView.setImageDrawable(new ColorDrawable(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this))); |
116 | | - } |
117 | | - }.execute(); |
118 | | - } |
119 | | - |
120 | | - Boolean isFullscreen = app.getBooleanPreference(this, AppData.PreferenceIdentifier.FULLSCREEN); |
121 | | - fullscreenSwitch.setChecked(isFullscreen != null && isFullscreen); |
122 | | - |
123 | | - fullscreenSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
124 | | - @Override |
125 | | - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
126 | | - app.putPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.FULLSCREEN, isChecked); |
127 | | - adapter.notifyDataSetChanged(); |
128 | | - } |
129 | | - }); |
130 | | - |
131 | | - Boolean isNotifications = app.getSpecificBooleanPreference(this, AppData.PreferenceIdentifier.NOTIFICATIONS); |
132 | | - notificationSwitch.setChecked(isNotifications == null || isNotifications); |
133 | | - |
134 | | - notificationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
135 | | - @Override |
136 | | - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
137 | | - app.putSpecificPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.NOTIFICATIONS, isChecked); |
| 21 | + public void onDismiss(DialogInterface dialog) { |
| 22 | + finish(); |
138 | 23 | } |
139 | 24 | }); |
140 | | - |
141 | | - recycler.setLayoutManager(new GridLayoutManager(this, 1)); |
142 | | - recycler.setNestedScrollingEnabled(false); |
143 | | - |
144 | | - adapter = new ActivityAdapter(this, app.activities); |
145 | | - recycler.setAdapter(adapter); |
146 | | - |
147 | | - if (intent.hasExtra(EXTRA_ACTIVITY)) { |
148 | | - activity = intent.getParcelableExtra(EXTRA_ACTIVITY); |
149 | | - |
150 | | - new Action<Integer>() { |
151 | | - @NonNull |
152 | | - @Override |
153 | | - public String id() { |
154 | | - return "activityColorDialog"; |
155 | | - } |
156 | | - |
157 | | - @Nullable |
158 | | - @Override |
159 | | - protected Integer run() throws InterruptedException { |
160 | | - return ColorUtils.getPrimaryColor(AppSettingActivity.this, activity.getComponentName()); |
161 | | - } |
162 | | - |
163 | | - @Override |
164 | | - protected void done(@Nullable Integer result) { |
165 | | - if (activity == null) return; |
166 | | - |
167 | | - ColorPickerDialog dialog = new ColorPickerDialog(AppSettingActivity.this); |
168 | | - dialog.setPreference(activity.getIntegerPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR)); |
169 | | - dialog.setDefaultPreference(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this)); |
170 | | - dialog.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() { |
171 | | - @Override |
172 | | - public void onPreference(PreferenceDialog dialog, Integer preference) { |
173 | | - if (activity != null) { |
174 | | - activity.putPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR, preference); |
175 | | - adapter.notifyDataSetChanged(); |
176 | | - } |
177 | | - } |
178 | | - |
179 | | - @Override |
180 | | - public void onCancel(PreferenceDialog dialog) { |
181 | | - } |
182 | | - }); |
183 | | - dialog.show(); |
184 | | - } |
185 | | - }.execute(); |
186 | | - } |
187 | | - } |
188 | | - |
189 | | - @Override |
190 | | - public boolean onOptionsItemSelected(MenuItem item) { |
191 | | - switch (item.getItemId()) { |
192 | | - case android.R.id.home: |
193 | | - finish(); |
194 | | - break; |
195 | | - } |
196 | | - |
197 | | - return super.onOptionsItemSelected(item); |
| 25 | + dialog.show(); |
198 | 26 | } |
199 | 27 | } |
0 commit comments