-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,199 additions
and
203 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 65 additions & 58 deletions
123
app/src/main/java/ru/fazziclay/schoolguide/SettingsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,103 @@ | ||
package ru.fazziclay.schoolguide; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import com.google.android.material.snackbar.Snackbar; | ||
import androidx.preference.PreferenceFragmentCompat; | ||
import androidx.preference.PreferenceManager; | ||
|
||
import ru.fazziclay.schoolguide.app.SchoolGuideApp; | ||
import ru.fazziclay.schoolguide.app.Settings; | ||
import ru.fazziclay.schoolguide.databinding.SettingsActivityBinding; | ||
import ru.fazziclay.schoolguide.app.global.AutoGlobalUpdateService; | ||
import ru.fazziclay.schoolguide.app.listener.PresetListUpdateListener; | ||
import ru.fazziclay.schoolguide.callback.CallbackStorage; | ||
import ru.fazziclay.schoolguide.callback.Status; | ||
|
||
public class SettingsActivity extends AppCompatActivity { | ||
private static final String KEY_IS_DEVELOPER_FEATURES = "isDeveloperFeatures"; | ||
private static final String KEY_IS_BUILTIN_PRESET_LIST = "isBuiltinPresetList"; | ||
private static final String KEY_IS_SHOW_EMPTY_NOTIFICATION = "isShowEmptyNotification"; | ||
|
||
public static Intent getLaunchIntent(Context context) { | ||
return new Intent(context, SettingsActivity.class); | ||
} | ||
|
||
private SchoolGuideApp app; | ||
private Settings settings; | ||
private SettingsActivityBinding binding; | ||
|
||
private SharedPreferences preferences; | ||
|
||
private final SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, key) -> { | ||
boolean contains = sharedPreferences.contains(key); | ||
if (!contains) return; | ||
|
||
switch (key) { | ||
case KEY_IS_DEVELOPER_FEATURES: | ||
settings.isDeveloperFeatures = sharedPreferences.getBoolean(key, false); | ||
break; | ||
|
||
case KEY_IS_BUILTIN_PRESET_LIST: | ||
settings.isBuiltInPresetList = sharedPreferences.getBoolean(key, false); | ||
AutoGlobalUpdateService.update(app); | ||
break; | ||
|
||
case KEY_IS_SHOW_EMPTY_NOTIFICATION: | ||
settings.isStopForegroundIsNone = !sharedPreferences.getBoolean(key, false); | ||
break; | ||
} | ||
app.saveSettings(); | ||
app.getPresetListUpdateCallbacks().run((callbackStorage, callback) -> callback.onPresetListUpdate()); | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
app = SchoolGuideApp.get(this); | ||
if (app == null) { | ||
setContentView(SharedConstrains.getAppNullView(this)); | ||
return; | ||
} | ||
settings = app.getSettings(); | ||
|
||
binding = SettingsActivityBinding.inflate(getLayoutInflater()); | ||
setContentView(binding.getRoot()); | ||
setContentView(R.layout.activity_settings); | ||
setTitle(R.string.settings_activityTitle); | ||
|
||
if (savedInstanceState == null) { | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.settings, new SettingsFragment()) | ||
.commit(); | ||
} else { | ||
Toast.makeText(this, "Error", Toast.LENGTH_LONG).show(); | ||
finish(); | ||
return; | ||
} | ||
|
||
setActualState(settings); | ||
setCallbacks(); | ||
} | ||
preferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
preferences.edit() | ||
.putBoolean(KEY_IS_SHOW_EMPTY_NOTIFICATION, !settings.isStopForegroundIsNone) | ||
.putBoolean(KEY_IS_DEVELOPER_FEATURES, settings.isDeveloperFeatures) | ||
.putBoolean(KEY_IS_BUILTIN_PRESET_LIST, settings.isBuiltInPresetList) | ||
.apply(); | ||
|
||
private void setActualState(Settings settings) { | ||
binding.developerFeatures.setChecked(settings.developerFeatures); | ||
binding.stopForegroundIsNone.setChecked(settings.stopForegroundIsNone); | ||
binding.isFirstMonday.setChecked(settings.isFirstMonday); | ||
binding.syncGlobalPresetList.setChecked(settings.globalPresetListSync); | ||
preferences.registerOnSharedPreferenceChangeListener(listener); | ||
} | ||
|
||
private void setCallbacks() { | ||
binding.developerFeatures.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||
settings.developerFeatures = isChecked; | ||
save(); | ||
}); | ||
|
||
binding.stopForegroundIsNone.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||
settings.stopForegroundIsNone = isChecked; | ||
save(); | ||
}); | ||
|
||
binding.isFirstMonday.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||
settings.isFirstMonday = isChecked; | ||
save(); | ||
}); | ||
|
||
binding.syncGlobalPresetList.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||
settings.globalPresetListSync = isChecked; | ||
save(); | ||
}); | ||
|
||
binding.changeScheduleNotifyBeforeTime.setOnClickListener(v -> { | ||
EditText editText = new EditText(this); | ||
editText.setText(String.valueOf(settings.scheduleNotifyBeforeTime)); | ||
|
||
new AlertDialog.Builder(this) | ||
.setView(editText) | ||
.setPositiveButton("APPLY", (ig, ign) -> { | ||
try { | ||
settings.scheduleNotifyBeforeTime = Integer.parseInt(editText.getText().toString()); | ||
} catch (Exception e) { | ||
app.getAppTrace().point("changeScheduleNotifyBeforeTimeDialog", e); | ||
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show(); | ||
} | ||
save(); | ||
}) | ||
.show(); | ||
}); | ||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
preferences.unregisterOnSharedPreferenceChangeListener(listener); | ||
} | ||
|
||
private void save() { | ||
app.saveSettings(); | ||
Snackbar snackbar = Snackbar.make(binding.getRoot(), "Saved!", Snackbar.LENGTH_SHORT); | ||
snackbar.show(); | ||
public static class SettingsFragment extends PreferenceFragmentCompat { | ||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
setPreferencesFromResource(R.xml.settings_preferences, rootKey); | ||
} | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
app/src/main/java/ru/fazziclay/schoolguide/app/AppBuiltinSchedule.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...schoolguide/app/GlobalUpdateListener.java → ...de/app/listener/GlobalUpdateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/ru/fazziclay/schoolguide/app/listener/PresetListUpdateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ru.fazziclay.schoolguide.app.listener; | ||
|
||
import ru.fazziclay.schoolguide.callback.Callback; | ||
import ru.fazziclay.schoolguide.callback.Status; | ||
|
||
public interface PresetListUpdateListener extends Callback { | ||
Status onPresetListUpdate(); | ||
} |
Oops, something went wrong.