From c88f2a39ce3bccbe5491fc1889e674d994d8d8cc Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 8 Sep 2018 03:49:56 +0300 Subject: [PATCH] Init changelog dialog --- app/src/main/assets/changelog.json | 97 +++++++++++ .../mthmmy/activities/main/MainActivity.java | 15 +- .../java/gr/thmmy/mthmmy/utils/Changelog.java | 155 ++++++++++++++++++ .../twitter_unicode_alien_monster.xml | 27 +++ app/src/main/res/layout/dialog_changelog.xml | 85 ++++++++++ app/src/main/res/values/colors.xml | 7 + app/src/main/res/values/strings.xml | 7 + 7 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 app/src/main/assets/changelog.json create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/Changelog.java create mode 100644 app/src/main/res/drawable/twitter_unicode_alien_monster.xml create mode 100644 app/src/main/res/layout/dialog_changelog.xml diff --git a/app/src/main/assets/changelog.json b/app/src/main/assets/changelog.json new file mode 100644 index 00000000..d0c7c213 --- /dev/null +++ b/app/src/main/assets/changelog.json @@ -0,0 +1,97 @@ +{ + "changelogs": [ + { + "version_code": 13, + "version": "5.0.0", + "release_date": "Someday in september.... hopefully", + "video": "Maybe someday", + "prelude": "May be useful sometimes.. like a text above the actual change list", + "change_list": [ + { + "change": "feature", + "title": "Brand new editor view ARISES!", + "description": "Take advantage of the new post content editor to post like you never before. (hint: it can emoji)" + }, + { + "change": "feature", + "title": "Uploads!", + "description": "Yes, it's true, you can now upload files. Small files, big files. It's really up to you." + }, + { + "change": "feature", + "title": "New topics ooooonnn the wayyyyy.", + "description": "It was something missing." + }, + { + "change": "feature", + "title": "Postal manipulation.", + "description": "Edit or delete your posts, if you dare." + }, + { + "change": "feature", + "title": "Quotes: year 2018.", + "description": "You can quote from multiple pages. We did this too, just because." + }, + { + "change": "feature", + "title": "Tweak it.", + "description": "Settings are now available, in case you want to change your notifications sound." + }, + { + "change": "feature", + "title": "OMG this is a long changelog!!", + "description": "Well get used to it, we have ultra cool changelogs now!" + }, + { + "change": "bug", + "title": "Unread posts missing.", + "description": "Know how you could only see the first page of your unread messages? Not anymore!" + },{ + "change": "bug", + "title": "Many bugs.", + "description": "We fixed a ton of other bugs to the app is now like 36.2% more bug free." + }, + { + "change": "improvement", + "title": "Much cutter icons in boards.", + "description": "Sticky icon changed to much the overall greatness of the forum, also a dot was added. Don't you just love dots?" + }, + { + "change": "improvement", + "title": "Post actions overflow.", + "description": "We noticed how post cards were getting cramped up by all the quote buttons and whatnot, so we moved some to an overflow." + }, + { + "change": "improvement", + "title": "Vectors once again.", + "description": "All icons are now in vector format. No zoom is scary in this parts!" + }, + { + "change": "improvement", + "title": "Reporting.", + "description": "Long overdue job was done in the reporting class. We shall now have an easier time fixing bothering bugs." + }, + { + "change": "improvement", + "title": "No wifi, no topic.", + "description": "Added a message in topics that warns when no connection is available." + }, + { + "change": "improvement", + "title": "Get mentioned.", + "description": "A yellow border is added to posts that quote you. It's beautiful!" + }, + { + "change": "improvement", + "title": "The inner update.", + "description": "Updated the libraries used. So expect 4% better behavior." + }, + { + "change": "undef", + "title": "You made it!", + "description": "Congrats, this is the end.. of the changelog! Have a cookie \uD83C\uDF6A" + } + ] + } + ] +} \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index 4ffc3dff..4fdc4543 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.main; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -9,7 +10,10 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.AlertDialog; import android.support.v7.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.widget.LinearLayout; import android.widget.Toast; import java.util.ArrayList; @@ -28,6 +32,7 @@ import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicSummary; +import gr.thmmy.mthmmy.utils.Changelog; import timber.log.Timber; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; @@ -41,7 +46,8 @@ import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; -public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { +public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, + ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { //-----------------------------------------CLASS VARIABLES------------------------------------------ private static final int TIME_INTERVAL = 2000; @@ -92,6 +98,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } setMainActivity(this); + + if (Changelog.getLaunchType(this) == Changelog.LAUNCH_TYPE.FIRST_LAUNCH_AFTER_UPDATE) { + AlertDialog dialog = Changelog.getChangelogDialog(this); + dialog.show(); + } } @Override @@ -104,7 +115,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF @Override protected void onResume() { drawer.setSelection(HOME_ID); - if(!sharedPrefs.getBoolean(DRAWER_INTRO, false)){ + if (!sharedPrefs.getBoolean(DRAWER_INTRO, false)) { drawer.openDrawer(); sharedPrefs.edit().putBoolean(DRAWER_INTRO, true).apply(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/Changelog.java b/app/src/main/java/gr/thmmy/mthmmy/utils/Changelog.java new file mode 100644 index 00000000..ae3d7615 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/Changelog.java @@ -0,0 +1,155 @@ +package gr.thmmy.mthmmy.utils; + +import android.content.Context; +import android.content.SharedPreferences; +import android.support.annotation.Nullable; +import android.support.v7.app.AlertDialog; +import android.support.v7.preference.PreferenceManager; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; +import android.view.LayoutInflater; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; + +import gr.thmmy.mthmmy.BuildConfig; +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.activities.main.MainActivity; +import timber.log.Timber; + +public class Changelog { + public enum LAUNCH_TYPE { + FIRST_LAUNCH_EVER, FIRST_LAUNCH_AFTER_UPDATE, NORMAL_LAUNCH + } + + private static final String PREF_VERSION_CODE_KEY = "VERSION_CODE"; + + @Nullable + public static LAUNCH_TYPE getLaunchType(Context context) { + final int notThere = -1; + + //Gets current version code + int currentVersionCode = BuildConfig.VERSION_CODE; + //Gets saved version code + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int savedVersionCode = prefs.getInt(PREF_VERSION_CODE_KEY, notThere); + + //Checks for first run or upgrade + if (currentVersionCode == savedVersionCode) { + //This is just a normal run + return LAUNCH_TYPE.NORMAL_LAUNCH; + } else if (savedVersionCode == notThere) { + //Updates the shared preferences with the current version code + prefs.edit().putInt(PREF_VERSION_CODE_KEY, currentVersionCode).apply(); + return LAUNCH_TYPE.FIRST_LAUNCH_EVER; + } else if (currentVersionCode > savedVersionCode) { + //Updates the shared preferences with the current version code + prefs.edit().putInt(PREF_VERSION_CODE_KEY, currentVersionCode).apply(); + return LAUNCH_TYPE.FIRST_LAUNCH_AFTER_UPDATE; + } + //Manually changed the shared prefs?? Omg + return null; + } + + public static AlertDialog getChangelogDialog(Context context) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + LayoutInflater inflater = ((MainActivity) context).getLayoutInflater(); + LinearLayout changelogView = (LinearLayout) inflater.inflate(R.layout.dialog_changelog, null); + + builder.setNegativeButton(R.string.dialog_not_interested_button, (dialog, which) -> dialog.dismiss()); + + try { + JSONObject jsonObject = new JSONObject(loadJSONFromAssets(context)); + JSONArray jsonArray = jsonObject.getJSONArray("changelogs"); + + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObjectInner = jsonArray.getJSONObject(i); + int versionCode = jsonObjectInner.getInt("version_code"); + + if (versionCode == BuildConfig.VERSION_CODE) { + TextView version = changelogView.findViewById(R.id.version); + version.setText(context.getResources().getString(R.string.changelog_version_text, + jsonObjectInner.getString("version"))); + + TextView releaseDate = changelogView.findViewById(R.id.release_date); + releaseDate.setText(jsonObjectInner.getString("release_date")); + + LinearLayout changeListView = changelogView.findViewById(R.id.changelog_content); + + JSONArray changeList = jsonObjectInner.getJSONArray("change_list"); + for (int changeIndex = 0; changeIndex < changeList.length(); ++changeIndex) { + TextView changeText = new TextView(changeListView.getContext()); + changeText.setTextColor(context.getResources().getColor(R.color.primary_text)); + LinearLayout.LayoutParams params = new LinearLayout. + LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + params.setMargins(0, 5, 0, 5); + changeText.setLayoutParams(params); + + JSONObject change = changeList.getJSONObject(changeIndex); + String changeType = change.getString("change"), + changeTitle = change.getString("title"), + changeDescription = change.getString("description"); + int changeColor; + + switch (changeType) { + case "feature": + changeColor = R.color.changelog_feature_dot; + break; + case "bug": + changeColor = R.color.changelog_bug_dot; + break; + case "improvement": + changeColor = R.color.changelog_improvement_dot; + break; + default: + changeColor = R.color.changelog_default_dot; + break; + } + + SpannableStringBuilder spannable = new SpannableStringBuilder("• " + + changeTitle + " " + changeDescription); + spannable.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), + 0, changeTitle.length() + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(changeColor)), + 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + + changeText.setText(spannable); + changeListView.addView(changeText); + } + break; + } + } + } catch (JSONException exception) { + Timber.e(exception, "Couldn't read changelog json from assets"); + } + + builder.setView(changelogView); + return builder.create(); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + private static String loadJSONFromAssets(Context context) { + String json; + try { + InputStream is = context.getAssets().open("changelog.json"); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + json = new String(buffer, "UTF-8"); + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + return json; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/twitter_unicode_alien_monster.xml b/app/src/main/res/drawable/twitter_unicode_alien_monster.xml new file mode 100644 index 00000000..e6f63dbf --- /dev/null +++ b/app/src/main/res/drawable/twitter_unicode_alien_monster.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_changelog.xml b/app/src/main/res/layout/dialog_changelog.xml new file mode 100644 index 00000000..932937f6 --- /dev/null +++ b/app/src/main/res/layout/dialog_changelog.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c3bdac7a..042d7a1b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -26,4 +26,11 @@ #D92B2B2B #E91E63 @color/primary_text + + + #17C723 + + #DE0607 + #772BB2 + @color/accent diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4b8013a4..766041d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -180,4 +180,11 @@ Link URL Link text Required + + + mascot + Human, I bring good news. + v. %1$s + Your software has been updated! + Cool, thanx for awesome app