Browse Source

Init changelog dialog

changelog
Apostolos Fanakis 6 years ago
parent
commit
c88f2a39ce
  1. 97
      app/src/main/assets/changelog.json
  2. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 155
      app/src/main/java/gr/thmmy/mthmmy/utils/Changelog.java
  4. 27
      app/src/main/res/drawable/twitter_unicode_alien_monster.xml
  5. 85
      app/src/main/res/layout/dialog_changelog.xml
  6. 7
      app/src/main/res/values/colors.xml
  7. 7
      app/src/main/res/values/strings.xml

97
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"
}
]
}
]
}

15
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();
}

155
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;
}
}

27
app/src/main/res/drawable/twitter_unicode_alien_monster.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="47.5dp"
android:height="47.5dp"
android:viewportHeight="47.5"
android:viewportWidth="47.5">
<group
android:scaleX="1.25"
android:scaleY="-1.25"
android:translateY="47.5">
<path
android:fillColor="#553986"
android:pathData="M31 6l-4 0 0 -4 4 0 0 4z" />
<path
android:fillColor="#553986"
android:pathData="M7 2L11 2 11 6 7 6 7 2Z" />
<path
android:fillColor="#553986"
android:pathData="M21 24l4 0 0 -8 -4 0 0 8zm-4 -8l-4 0 0 8 4 0 0 -8zm14 11l-2 0 0 2 -2 0 0 2 -3 0 0 4 -2 0 0 -4 -6 0 0 4 -2 0 0 -4 -3 0 0 -2 -2 0 0 -2 -2 0 0 -7 -4 0 0 -2 4 0 0 -7 4 0 0 -5 5 0 0 5 6 0 0 -5 5 0 0 5 4 0 0 7 4 0 0 2 -4 0 0 7z" />
<path
android:fillColor="#553986"
android:pathData="M35 20l2 0 0 11 -2 0 0 -11z" />
<path
android:fillColor="#553986"
android:pathData="M1 20L3 20 3 31 1 31 1 20Z" />
</group>
</vector>

85
app/src/main/res/layout/dialog_changelog.xml

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:orientation="vertical"
android:paddingEnd="12dp"
android:paddingStart="12dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:contentDescription="@string/alien_monster_mascot_description"
app:srcCompat="@drawable/twitter_unicode_alien_monster" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="47.5dp"
android:layout_weight="1"
android:gravity="bottom"
android:text="@string/alien_monster_mascot_speech"
android:textColor="@color/primary_text"
app:autoSizeTextType="uniform" />
</LinearLayout>
<!-- Video might go here -->
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="8dp"
android:singleLine="true"
android:text="@string/changelog_subtitle"
android:textColor="@color/accent"
app:autoSizeTextType="uniform" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
android:background="@color/accent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:orientation="horizontal">
<TextView
android:id="@+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/secondary_text"
android:textSize="12sp" />
<TextView
android:id="@+id/release_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textEnd"
android:textColor="@color/secondary_text"
android:textSize="12sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/changelog_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:orientation="vertical" />
</ScrollView>
</LinearLayout>

7
app/src/main/res/values/colors.xml

@ -26,4 +26,11 @@
<color name="dialog_bg_semi_transparent_dark">#D92B2B2B</color>
<color name="member_of_the_month">#E91E63</color>
<color name="topic_post_icon">@color/primary_text</color>
<!--<color name="changelog_feature_dot">#658550</color>-->
<color name="changelog_feature_dot">#17C723</color>
<!--<color name="changelog_bug_dot">#af1d1d</color>-->
<color name="changelog_bug_dot">#DE0607</color>
<color name="changelog_improvement_dot">#772BB2</color>
<color name="changelog_default_dot">@color/accent</color>
</resources>

7
app/src/main/res/values/strings.xml

@ -180,4 +180,11 @@
<string name="dialog_link_url_hint">Link URL</string>
<string name="dialog_link_text_hint">Link text</string>
<string name="input_field_required">Required</string>
<!-- Changelog -->
<string name="alien_monster_mascot_description">mascot</string>
<string name="alien_monster_mascot_speech">Human, I bring good news.</string>
<string name="changelog_version_text">v. %1$s</string>
<string name="changelog_subtitle">Your software has been updated!</string>
<string name="dialog_not_interested_button">Cool, thanx for awesome app</string>
</resources>

Loading…
Cancel
Save