-
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.
Add "Settings" activity for clearing progress
- Loading branch information
Showing
11 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/net/meyfa/statuscodestrainer/activities/settings/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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.meyfa.statuscodestrainer.activities.settings; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
public class SettingsActivity extends AppCompatActivity | ||
{ | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
|
||
// load the fragment as the main content | ||
getFragmentManager().beginTransaction()// | ||
.replace(android.R.id.content, new SettingsFragment())// | ||
.commit(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/java/net/meyfa/statuscodestrainer/activities/settings/SettingsFragment.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,76 @@ | ||
package net.meyfa.statuscodestrainer.activities.settings; | ||
|
||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceFragment; | ||
import android.support.v7.app.AlertDialog; | ||
import android.widget.Toast; | ||
|
||
import net.meyfa.statuscodestrainer.R; | ||
import net.meyfa.statuscodestrainer.logic.progress.ProgressTracker; | ||
import net.meyfa.statuscodestrainer.util.async.ActivityActionRunner; | ||
import net.meyfa.statuscodestrainer.util.async.AsyncAction; | ||
import net.meyfa.statuscodestrainer.util.async.Callback; | ||
|
||
public class SettingsFragment extends PreferenceFragment | ||
{ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
addPreferencesFromResource(R.xml.preferences); | ||
|
||
// clear progress | ||
Preference clearProgress = findPreference(getString(R.string.preference_clear_progress)); | ||
clearProgress.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() | ||
{ | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) | ||
{ | ||
showClearConfirmation(); | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
private void showClearConfirmation() | ||
{ | ||
new AlertDialog.Builder(getActivity())// | ||
.setTitle(R.string.clear_progress_title)// | ||
.setMessage(R.string.clear_progress_message)// | ||
.setIcon(android.R.drawable.ic_dialog_alert)// | ||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() | ||
{ | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) | ||
{ | ||
clearProgress(); | ||
} | ||
})// | ||
.setNegativeButton(android.R.string.no, null)// | ||
.show(); | ||
} | ||
|
||
private void clearProgress() | ||
{ | ||
new ActivityActionRunner<>(getActivity(), new AsyncAction<Void>() | ||
{ | ||
@Override | ||
protected Void execute() | ||
{ | ||
ProgressTracker tracker = ProgressTracker.getInstance(getActivity().getApplicationContext()); | ||
tracker.clearItems(); | ||
|
||
return null; | ||
} | ||
}).run(new Callback<Void>() | ||
{ | ||
@Override | ||
public void done(Void aVoid) | ||
{ | ||
Toast.makeText(getActivity(), R.string.clear_progress_toast, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<item | ||
android:id="@+id/menu_item_settings" | ||
android:title="@string/main_menu_item_settings" | ||
app:showAsAction="never" /> | ||
|
||
</menu> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<Preference | ||
android:key="@string/preference_clear_progress" | ||
android:title="@string/preference_clear_progress_label" /> | ||
</PreferenceScreen> |