Skip to content

Commit

Permalink
Added reset settings and improvements
Browse files Browse the repository at this point in the history
-Added reset settings button
-Added sleep time options
-Changed default sleep time from 10 minutes to 1 hour
-Added message no news if after update there are no news
  • Loading branch information
Baldi00 committed May 5, 2019
1 parent 07c64f0 commit 6360e47
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ public class ActivitySettings extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setSettingsGraphic();
}

@Override
public void onPause() {
super.onPause();
if(toApplyChanges)
applyChanges(null);
}

public void setSettingsGraphic(){
try {
settingsManager = SettingsManager.getInstance();
notificationServiceEnabled = settingsManager.isNotificationServiceEnabled();
Expand All @@ -42,9 +52,7 @@ public void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}

if(!notificationServiceEnabled){
((Switch)findViewById(R.id.notificationServiceEnabled)).setChecked(false);
}
((Switch)findViewById(R.id.notificationServiceEnabled)).setChecked(notificationServiceEnabled);

Spinner spinner = (Spinner)findViewById(R.id.notificationServiceSleepTime);
switch (notificationServiceSleepTime){
Expand All @@ -60,29 +68,22 @@ public void onCreate(Bundle savedInstanceState) {
case 10800000:
spinner.setSelection(3);
break;
case 5000:
case 21600000:
spinner.setSelection(4);
break;
case 43200000:
spinner.setSelection(5);
break;
case 5000:
spinner.setSelection(6);
break;
}

if(!updateOnStartEnabled){
((Switch)findViewById(R.id.updateOnStartEnabled)).setChecked(false);
}

if(bunnyEnabled){
((Switch)findViewById(R.id.bunnyEnabled)).setChecked(true);
}
((Switch)findViewById(R.id.updateOnStartEnabled)).setChecked(updateOnStartEnabled);

if(notificationSoundEnabled){
((Switch)findViewById(R.id.notificationSoundEnabled)).setChecked(true);
}
}
((Switch)findViewById(R.id.bunnyEnabled)).setChecked(bunnyEnabled);

@Override
public void onPause() {
super.onPause();
if(toApplyChanges)
applyChanges(null);
((Switch)findViewById(R.id.notificationSoundEnabled)).setChecked(notificationSoundEnabled);
}

public void deleteTempGames(View v){
Expand Down Expand Up @@ -149,6 +150,35 @@ public void onClick(DialogInterface dialog, int which) {
dialog.show();
}

public void resetSettings(View v){
AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.DialogActivityGamePage);
dialog.setMessage("Vuoi ripristinare le impostazioni di default?");
dialog.setPositiveButton(
"Si",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
try {
settingsManager.resetSettings();
setSettingsGraphic();
} catch (Exception e) {
e.printStackTrace();
}
}
});

dialog.setNegativeButton(
"No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
}

public void resetAll(View v){
AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.DialogActivityGamePage);
dialog.setMessage("L'app verrà ripristinata e tutti i giochi verranno cancellati! Sei sicuro di voler ritornare allo stato iniziale?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class MyOnRefreshListener implements SwipeRefreshLayout.OnRefreshListener
private ActivityMain main;
private int notificationId;
private SettingsManager settingsManager;
private int numNotifications;

public MyOnRefreshListener(SwipeRefreshLayout pullToRefresh, ActivityMain main) {
this.pullToRefresh = pullToRefresh;
Expand All @@ -41,10 +42,9 @@ public MyOnRefreshListener(SwipeRefreshLayout pullToRefresh, ActivityMain main)
//Call the update for the games in wishlist
@Override
public void onRefresh() {
numNotifications = 0;
Updater up = new Updater(main,this);
up.execute();

//pullToRefresh.setRefreshing(false);
}

private void onEndRefresh(Boolean result){
Expand All @@ -53,10 +53,14 @@ private void onEndRefresh(Boolean result){


if(result!=null)
if(result)
Toast.makeText(main,"Aggiornamento terminato correttamente",Toast.LENGTH_SHORT).show();
else
Toast.makeText(main,"Non sei connesso a internet",Toast.LENGTH_SHORT).show();
if(result) {
Toast.makeText(main, "Aggiornamento terminato correttamente", Toast.LENGTH_SHORT).show();
if(numNotifications==0){
Toast.makeText(main, "Non ci sono novità", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(main, "Non sei connesso a internet", Toast.LENGTH_SHORT).show();
}
}

private class Updater extends AsyncTask {
Expand Down Expand Up @@ -96,6 +100,8 @@ protected Object doInBackground(Object[] objects) {

for (String str : notifications) {

numNotifications++;

//Read notification id
BufferedReader br = new BufferedReader(new FileReader(DirectoryManager.getAppDir() + "notificationId.txt"));
notificationId = Integer.parseInt(br.readLine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static SettingsManager getInstance() throws IOException {
private void createSettingsFile() throws IOException {

notificationServiceEnabled = true;
notificationServiceSleepTime = 600000;
notificationServiceSleepTime = 3600000;
notificationSoundEnabled = false;
updateOnStartEnabled = true;
bunnyEnabled = false;
Expand Down
29 changes: 24 additions & 5 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:paddingBottom="10dp">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -181,7 +182,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
android:paddingLeft="10dp"
android:paddingRight="10dp">

<Button
android:layout_width="match_parent"
Expand All @@ -195,7 +197,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
android:paddingLeft="10dp"
android:paddingRight="10dp">

<Button
android:layout_width="match_parent"
Expand All @@ -209,12 +212,28 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
android:paddingLeft="10dp"
android:paddingRight="10dp">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RIPRISTINA IMPOSTAZIONI"
android:onClick="resetSettings"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RESET"
android:text="RESET APP"
android:onClick="resetAll"/>

</LinearLayout>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<item>30 minuti</item>
<item>1 ora</item>
<item>3 ore</item>
<item>6 ore</item>
<item>12 ore</item>
<!--<item>5 secondi TEST</item>-->
</string-array>

Expand Down

0 comments on commit 6360e47

Please sign in to comment.