Skip to content

Commit

Permalink
Prepare for continuous delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Feb 16, 2024
1 parent b5bb3a8 commit c0b94c2
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 324 deletions.
101 changes: 23 additions & 78 deletions app/src/main/java/mobi/maptrek/dialogs/WhatsNew.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Andrey Novikov
* Copyright 2024 Andrey Novikov
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand All @@ -20,7 +20,6 @@
import android.app.Dialog;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -36,23 +35,18 @@
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.Collections;

import mobi.maptrek.Configuration;
import mobi.maptrek.MapTrek;
import mobi.maptrek.R;

public class WhatsNew extends DialogFragment {
private static final String TAG_CHANGELOG = "changelog";
private static final String TAG_RELEASE = "release";
private static final String TAG_CHANGE = "change";
private static final String ATTRIBUTE_VERSION_CODE = "versioncode";
private static final String ATTRIBUTE_VERSION = "version";
private static final String ATTRIBUTE_DATE = "date";
private static final String ATTRIBUTE_PRIORITY = "priority";

private final ArrayList<ChangeListItem> mChangelog = new ArrayList<>();

Expand All @@ -78,8 +72,15 @@ public void show(@NonNull FragmentManager manager, String tag) {
MapTrek application = MapTrek.getApplication();
int lastCode = Configuration.getLastSeenChangelog();
getChangelog(application, lastCode);
if (mChangelog.size() > 0)
super.show(manager, tag);
if (mChangelog.size() > 0) {
Collections.sort(mChangelog, (o1, o2) -> {
int result = Integer.compare(o1.priority, o2.priority);
if (result == 0)
result = Integer.compare(o2.version, o1.version);
return result;
});
super.show(manager, tag);
}
}

public static boolean shouldShow() {
Expand All @@ -103,17 +104,19 @@ private void getChangelog(MapTrek application, int version) {
continue;
}
String name = parser.getName();
if (name.equals(TAG_RELEASE)) {
if (name.equals(TAG_CHANGE)) {
parser.require(XmlPullParser.START_TAG, null, TAG_CHANGE);
int code = Integer.parseInt(parser.getAttributeValue(null, ATTRIBUTE_VERSION_CODE));
if (code > version) {
ChangeListItem changeItem = new ChangeListItem();
changeItem.version = parser.getAttributeValue(null, ATTRIBUTE_VERSION);
changeItem.date = parser.getAttributeValue(null, ATTRIBUTE_DATE);
changeItem.version = code;
changeItem.priority = Integer.parseInt(parser.getAttributeValue(null, ATTRIBUTE_PRIORITY));
changeItem.change = readText(parser);
mChangelog.add(changeItem);
readRelease(parser);
} else {
skip(parser);
}
parser.require(XmlPullParser.END_TAG, null, TAG_CHANGE);
} else {
skip(parser);
}
Expand All @@ -123,26 +126,6 @@ private void getChangelog(MapTrek application, int version) {
}
}

private void readRelease(XmlResourceParser parser) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, null, TAG_RELEASE);
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals(TAG_CHANGE)) {
parser.require(XmlPullParser.START_TAG, null, TAG_CHANGE);
ChangeListItem changeItem = new ChangeListItem();
changeItem.change = readText(parser);
mChangelog.add(changeItem);
parser.require(XmlPullParser.END_TAG, null, TAG_CHANGE);
} else {
skip(parser);
}
}
parser.require(XmlPullParser.END_TAG, null, TAG_RELEASE);
}

@NonNull
private static String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
String result = "";
Expand Down Expand Up @@ -170,17 +153,6 @@ private static void skip(XmlPullParser parser) throws XmlPullParserException, IO
}
}

private String parseDate(final String dateString) {
final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
try {
final Date parsedDate = dateFormat.parse(dateString);
if (parsedDate != null)
return DateFormat.getDateFormat(getContext()).format(parsedDate);
} catch (ParseException ignored) {
}
return dateString;
}

private class ChangeListAdapter extends BaseAdapter {
@Override
public ChangeListItem getItem(int position) {
Expand Down Expand Up @@ -209,28 +181,14 @@ public View getView(final int position, View convertView, ViewGroup parent) {

if (convertView == null) {
itemHolder = new WhatsNew.ChangeListItemHolder();
if (item.version != null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_change_title, parent, false);
itemHolder.divider = convertView.findViewById(R.id.group_divider);
itemHolder.version = convertView.findViewById(R.id.version);
itemHolder.date = convertView.findViewById(R.id.date);
} else {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_change, parent, false);
itemHolder.change = convertView.findViewById(R.id.change);
}
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_change, parent, false);
itemHolder.change = convertView.findViewById(R.id.change);
convertView.setTag(itemHolder);
} else {
itemHolder = (WhatsNew.ChangeListItemHolder) convertView.getTag();
}

if (item.version != null) {
itemHolder.divider.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
itemHolder.version.setText(item.version);
if (item.date != null)
itemHolder.date.setText(parseDate(item.date));
} else {
itemHolder.change.setText(item.change);
}
itemHolder.change.setText(item.change);

return convertView;
}
Expand All @@ -239,28 +197,15 @@ public View getView(final int position, View convertView, ViewGroup parent) {
public boolean hasStableIds() {
return true;
}

@Override
public int getItemViewType(int position) {
return mChangelog.get(position).version != null ? 0 : 1;
}

@Override
public int getViewTypeCount() {
return 2;
}
}

private static class ChangeListItem {
String version;
String date;
int version;
int priority;
String change;
}

private static class ChangeListItemHolder {
View divider;
TextView version;
TextView date;
TextView change;
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/circle_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="18dp"
android:height="18dp"
android:drawable="@drawable/circle_accent"
android:gravity="center" />
</layer-list>
27 changes: 17 additions & 10 deletions app/src/main/res/layout/list_item_change.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:viewBindingIgnore="true">

<View
<TextView
android:id="@+id/circle"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/circle_accent" />
android:layout_height="wrap_content"
android:background="@drawable/circle_background"
app:layout_constraintBaseline_toBaselineOf="@+id/change"
app:layout_constraintEnd_toStartOf="@id/change"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/change"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/circle"
app:layout_constraintTop_toTopOf="parent"
tools:text="Added new cool feature" />
</androidx.constraintlayout.widget.ConstraintLayout>
32 changes: 0 additions & 32 deletions app/src/main/res/layout/list_item_change_title.xml

This file was deleted.

Loading

0 comments on commit c0b94c2

Please sign in to comment.