News opt-in done.

This commit is contained in:
Jens 2021-03-15 23:06:37 +01:00
parent c1f03d3395
commit 722f9f0e6b
5 changed files with 99 additions and 49 deletions

View File

@ -418,7 +418,34 @@ public class ActivityMainScreen extends ActivityGeneric
Miscellaneous.logEvent("i", "ActivityMainScreen", "Activity not running. No need to update.", 5); Miscellaneous.logEvent("i", "ActivityMainScreen", "Activity not running. No need to update.", 5);
if(activityMainScreenInstance != null) if(activityMainScreenInstance != null)
{
if(!Settings.hasBeenDone(Settings.constNewsOptInDone))
newsOptIn();
else
activityMainScreenInstance.checkForNews(); activityMainScreenInstance.checkForNews();
Settings.considerDone(Settings.constNewsOptInDone);
Settings.writeSettings(Miscellaneous.getAnyContext());
}
}
static void newsOptIn()
{
AlertDialog.Builder builder = new AlertDialog.Builder(Miscellaneous.getAnyContext());
builder.setMessage(Miscellaneous.getAnyContext().getResources().getString(R.string.newsOptIn));
builder.setPositiveButton(Miscellaneous.getAnyContext().getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Settings.displayNewsOnMainScreen = true;
Settings.writeSettings(Miscellaneous.getAnyContext());
activityMainScreenInstance.checkForNews();
}
});
builder.setNegativeButton(Miscellaneous.getAnyContext().getResources().getString(R.string.no), null);
builder.create().show();
} }
@Override @Override
@ -571,40 +598,15 @@ public class ActivityMainScreen extends ActivityGeneric
} }
synchronized void checkForNews() synchronized void checkForNews()
{
if(Settings.displayNewsOnMainScreen)
{ {
News.AsyncTaskDownloadNews dnTask = new News.AsyncTaskDownloadNews(); News.AsyncTaskDownloadNews dnTask = new News.AsyncTaskDownloadNews();
dnTask.execute(ActivityMainScreen.this); dnTask.execute(ActivityMainScreen.this);
}
// StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
// StrictMode.setThreadPolicy(policy);
// Calendar now = Calendar.getInstance();
// if (true || Settings.lastNewsPolltime == -1 || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.pollNewsEveryXDays * 24 * 60 * 60 * 1000))
// {
// ArrayList<News> newsToDisplay;
//
//// if(Settings.lastNewsPolltime == -1)
// newsToDisplay = News.downloadNews(ActivityMainScreen.this);
//// else
//// newsToDisplay = News.downloadNews(ActivityMainScreen.this, Miscellaneous.calendarFromLong(Settings.lastNewsPolltime));
//
// if (newsToDisplay.size() > 0)
// {
// activityMainScreenInstance.tvMainScreenNote3.setText(newsToDisplay.get(0).toString());
// activityMainScreenInstance.tvMainScreenNote3.setVisibility(View.VISIBLE);
// }
// else
// {
// activityMainScreenInstance.tvMainScreenNote3.setText("");
// activityMainScreenInstance.tvMainScreenNote3.setVisibility(View.GONE);
// }
// }
} }
public void processNewsResult(ArrayList<News> newsToDisplay) public void processNewsResult(ArrayList<News> newsToDisplay)
{
if(Settings.displayNewsOnMainScreen)
{ {
try try
{ {
@ -624,5 +626,4 @@ public class ActivityMainScreen extends ActivityGeneric
Miscellaneous.logEvent("e", "Error displaying news", Log.getStackTraceString(e), 3); Miscellaneous.logEvent("e", "Error displaying news", Log.getStackTraceString(e), 3);
} }
} }
}
} }

View File

@ -977,7 +977,7 @@ public class ActivityPermissions extends Activity
and simply disable features while keeping the notification alive. The user may dismiss it anyway. and simply disable features while keeping the notification alive. The user may dismiss it anyway.
*/ */
Miscellaneous.logEvent("w", "Denied permissions", getResources().getString(R.string.theFollowingPermissionsHaveBeenDenied) + Miscellaneous.explode(deniedPermissions), 3); Miscellaneous.logEvent("w", "Denied permissions", getResources().getString(R.string.theFollowingPermissionsHaveBeenDenied) + Miscellaneous.explode(", ", deniedPermissions), 3);
// this.finish(); // this.finish();
} }
else else

View File

@ -864,14 +864,22 @@ public class Miscellaneous extends Service
return builder; return builder;
} }
public static String explode(ArrayList<String> arrayList) public static String explode(String glue, ArrayList<String> arrayList)
{
if(arrayList != null)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for(String s : arrayList) for (String s : arrayList)
builder.append(s); builder.append(s + glue);
if (builder.length() > 0)
builder.delete(builder.length() - glue.length(), builder.length());
return builder.toString(); return builder.toString();
} }
else
return "";
}
public static boolean isGooglePlayInstalled(Context context) public static boolean isGooglePlayInstalled(Context context)
{ {

View File

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -16,6 +17,8 @@ public class Settings implements SharedPreferences
public static final int newsDisplayForXDays = 3; public static final int newsDisplayForXDays = 3;
public static final String folderName = "Automation"; public static final String folderName = "Automation";
public static final String constNewsOptInDone ="newsOptInDone";
public static long minimumDistanceChangeForGpsUpdate; public static long minimumDistanceChangeForGpsUpdate;
public static long minimumDistanceChangeForNetworkUpdate; public static long minimumDistanceChangeForNetworkUpdate;
public static long satisfactoryAccuracyGps; public static long satisfactoryAccuracyGps;
@ -62,6 +65,8 @@ public class Settings implements SharedPreferences
public static boolean noticeAndroid10WifiShown; public static boolean noticeAndroid10WifiShown;
public static long lastNewsPolltime; public static long lastNewsPolltime;
public static ArrayList<String> whatHasBeenDone;
/* /*
Generic settings valid for all installations and not changable Generic settings valid for all installations and not changable
*/ */
@ -250,6 +255,16 @@ public class Settings implements SharedPreferences
noticeAndroid10WifiShown = prefs.getBoolean("noticeAndroid10WifiShown", false); noticeAndroid10WifiShown = prefs.getBoolean("noticeAndroid10WifiShown", false);
lastNewsPolltime = prefs.getLong("lastNewsPolltime", default_lastNewsPolltime); lastNewsPolltime = prefs.getLong("lastNewsPolltime", default_lastNewsPolltime);
String whbdString = prefs.getString("whatHasBeenDone", "");
if(whbdString != null && whbdString.length() > 0)
{
whatHasBeenDone = new ArrayList<>();
for(String s : whbdString.split(";"))
{
whatHasBeenDone.add(s);
}
}
} }
catch(Exception e) catch(Exception e)
{ {
@ -262,6 +277,26 @@ public class Settings implements SharedPreferences
} }
} }
public static void considerDone(String key)
{
if(whatHasBeenDone == null)
whatHasBeenDone = new ArrayList<>();
if(!whatHasBeenDone.contains(key))
whatHasBeenDone.add(key);
}
public static boolean hasBeenDone(String key)
{
if(whatHasBeenDone != null)
{
if(whatHasBeenDone.contains(key))
return true;
}
return false;
}
/**Makes sure a settings has a valid setting. If not it will assign a reasonable default setting to it. /**Makes sure a settings has a valid setting. If not it will assign a reasonable default setting to it.
* If force settings will be initialized even if the user has set something.**/ * If force settings will be initialized even if the user has set something.**/
public static boolean initializeSettings(Context context, boolean force) public static boolean initializeSettings(Context context, boolean force)
@ -411,6 +446,9 @@ public class Settings implements SharedPreferences
if(!prefs.contains("lastNewsPolltime") | force) if(!prefs.contains("lastNewsPolltime") | force)
editor.putLong("lastNewsPolltime", default_lastNewsPolltime); editor.putLong("lastNewsPolltime", default_lastNewsPolltime);
if(!prefs.contains("whatHasBeenDone") | force)
editor.putString("whatHasBeenDone", "");
editor.commit(); editor.commit();
return true; return true;
@ -480,6 +518,8 @@ public class Settings implements SharedPreferences
editor.putLong("lastNewsPolltime", lastNewsPolltime); editor.putLong("lastNewsPolltime", lastNewsPolltime);
editor.putString("whatHasBeenDone", Miscellaneous.explode(";", whatHasBeenDone));
if(lastActivePoi == null) if(lastActivePoi == null)
editor.putString("lastActivePoi", "null"); editor.putString("lastActivePoi", "null");
else else

View File

@ -606,4 +606,5 @@
<string name="displayNewsOnMainScreen">Display application news on main screen</string> <string name="displayNewsOnMainScreen">Display application news on main screen</string>
<string name="displayNewsOnMainScreenDescription">Announcements about this app only, we\'re probably talking about 1-2 per year, not more.</string> <string name="displayNewsOnMainScreenDescription">Announcements about this app only, we\'re probably talking about 1-2 per year, not more.</string>
<string name="filesHaveBeenMovedTo">Automation now uses another path to store your files. All your Automation-files have been moved here: \"%s\". The external storage permission is not required anymore; you can revoke it. It will be removed in a future version.</string> <string name="filesHaveBeenMovedTo">Automation now uses another path to store your files. All your Automation-files have been moved here: \"%s\". The external storage permission is not required anymore; you can revoke it. It will be removed in a future version.</string>
<string name="newsOptIn">Would you like to receive (only important) news about this app on the main screen? Those are downloaded from the developer\'s website. There will be no intrusive notification, just a text on the main screen when you open the app.</string>
</resources> </resources>