Skip to content

Commit

Permalink
solve bug 0000285
Browse files Browse the repository at this point in the history
  • Loading branch information
domjos1994 committed Oct 29, 2019
1 parent 89d0ab8 commit ced0183
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TableLayout;
Expand All @@ -37,12 +36,10 @@
import com.github.angads25.filepicker.model.DialogConfigs;
import com.github.angads25.filepicker.model.DialogProperties;
import com.github.angads25.filepicker.view.FilePickerDialog;
import com.github.mikephil.charting.utils.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.file.Files;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package de.domjos.unitrackermobile.activities;

import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
Expand All @@ -26,16 +29,21 @@
import android.widget.Spinner;
import android.widget.TableRow;

import androidx.annotation.NonNull;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.io.File;
import java.util.Date;

import de.domjos.unitrackerlibrary.interfaces.IBugService;
import de.domjos.unitrackerlibrary.interfaces.IFunctionImplemented;
import de.domjos.unitrackerlibrary.model.ListObject;
import de.domjos.unitrackerlibrary.model.projects.Version;
import de.domjos.unitrackerlibrary.services.engine.Authentication;
import de.domjos.unitrackerlibrary.tasks.ExportTask;
import de.domjos.unitrackerlibrary.tasks.VersionTask;
import de.domjos.unitrackerlibrary.utils.Converter;
import de.domjos.unitrackerlibrary.utils.MessageHelper;
import de.domjos.unitrackermobile.R;
import de.domjos.unitrackermobile.custom.AbstractActivity;
Expand Down Expand Up @@ -277,6 +285,7 @@ private void updateUITrackerSpecific() {
if (tracker != null) {
switch (tracker) {
case MantisBT:
case Local:
this.rowVersionReleasedAt.setVisibility(View.VISIBLE);
this.rowVersionReleased.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
Expand All @@ -290,6 +299,7 @@ private void updateUITrackerSpecific() {
this.chkVersionDeprecated.setOnCheckedChangeListener((buttonView, isChecked) -> this.chkVersionReleased.setVisibility(isChecked ? View.GONE : View.VISIBLE));
break;
case YouTrack:
case OpenProject:
this.rowVersionReleasedAt.setVisibility(View.VISIBLE);
this.rowVersionReleased.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
Expand All @@ -307,23 +317,55 @@ private void updateUITrackerSpecific() {
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
break;
case OpenProject:
this.rowVersionReleasedAt.setVisibility(View.VISIBLE);
this.rowVersionReleased.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
break;
case Backlog:
this.rowVersionReleasedAt.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
break;
case Local:
this.rowVersionReleasedAt.setVisibility(View.VISIBLE);
this.rowVersionReleased.setVisibility(View.VISIBLE);
this.rowVersionDeprecated.setVisibility(View.VISIBLE);
this.rowVersionFilter.setVisibility(View.VISIBLE);
break;
}
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_versions, menu);
return true;
}

@Override
@SuppressWarnings("deprecation")
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
try {
if(item.getItemId()==R.id.menChangelog) {
if(this.currentVersion != null) {
String downloadDir = "";
File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
if(file!=null) {
downloadDir = file.getAbsolutePath();
}
Object vid = this.currentVersion.getId();
Object pid = this.currentProject;

byte[] bg, icon;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
bg = Converter.convertDrawableToByteArray(VersionActivity.this.getDrawable(R.drawable.background));
icon = Converter.convertDrawableToByteArray(VersionActivity.this.getDrawable(R.drawable.ic_launcher_web));
} else {
bg = Converter.convertDrawableToByteArray(VersionActivity.this.getResources().getDrawable(R.drawable.background));
icon = Converter.convertDrawableToByteArray(VersionActivity.this.getResources().getDrawable(R.drawable.ic_launcher_web));
}

ExportTask exportTask = new ExportTask(
VersionActivity.this, bugService, null, pid, downloadDir,
false, R.drawable.ic_bug_report_black_24dp, bg, icon, "", vid);
exportTask.execute(0).get();
MessageHelper.printMessage(this.getString(R.string.versions_menu_changelog_created), VersionActivity.this);
} else {
MessageHelper.printMessage(this.getString(R.string.versions_menu_changelog_no_selected), VersionActivity.this);
}
}
} catch (Exception ex) {
MessageHelper.printException(ex, VersionActivity.this);
}
return super.onOptionsItemSelected(item);
}
}
27 changes: 27 additions & 0 deletions app/src/main/res/menu/menu_versions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 Domjos
~ This file is part of UniTrackerMobile <https://github.com/domjos1994/UniTrackerMobile>.
~
~ UniTrackerMobile is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ UniTrackerMobile is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with UniTrackerMobile. If not, see <http://www.gnu.org/licenses/>.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menChangelog"
android:orderInCategory="100"
android:title="@string/versions_menu_changelog"
app:showAsAction="never" />
</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<item>@string/versions_unReleased</item>
<item>@string/versions_released</item>
</string-array>
<string name="versions_menu_changelog">Changelog-PDF generieren</string>
<string name="versions_menu_changelog_no_selected">Keine Version ausgewählt!</string>
<string name="versions_menu_changelog_created">Changelog wurde erfolgreich im Download-Ordner erstellt</string>

<string name="users">Benutzer</string>
<string name="users_login">Login-Name</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
<item>@string/versions_unReleased</item>
<item>@string/versions_released</item>
</string-array>
<string name="versions_menu_changelog">Create Changelog as PDF</string>
<string name="versions_menu_changelog_no_selected">No Version selected!</string>
<string name="versions_menu_changelog_created">Changelog was created successfully in Download-Folder!</string>

<string name="users">User</string>
<string name="users_login">Login-Name</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.AbstractMap;
Expand Down Expand Up @@ -73,6 +74,36 @@ static void saveObjectToPDF(List lst, String path, byte[] array, byte[] icon) th
pdfDocument.close();
}

static void createChangeLog(List<Issue> issues, String path, byte[] array, byte[] icon, Version version) throws Exception {
Map<String, Font> fonts = new LinkedHashMap<>();
fonts.put(H1, new Font(Font.FontFamily.HELVETICA, 18, Font.BOLDITALIC, BaseColor.BLACK));
fonts.put(H2, new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK));
fonts.put(H3, new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.BLACK));
fonts.put(BODY, new Font(Font.FontFamily.HELVETICA, 14, Font.NORMAL, BaseColor.BLACK));

Document pdfDocument = new Document();
PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(path + File.separatorChar + "changelog_" + version.getId() + ".pdf"));
writer.setBoxSize("art", new Rectangle(55, 25, 550, 788));
writer.setPageEvent(new PDFPageEvent(1, array, icon));
pdfDocument.open();
ObjectPDF.saveChangeLogToPDF(issues, pdfDocument, fonts, version);
pdfDocument.close();
}


private static void saveChangeLogToPDF(List<Issue> issues, Document pdfDocument, Map<String, Font> fonts, Version version) throws Exception {
pdfDocument.add(ObjectPDF.addTitle("Changelog of " + version.getTitle(), fonts.get(H1), Paragraph.ALIGN_CENTER));
pdfDocument.add(ObjectPDF.addEmptyLine(3));

List<List<Map.Entry<String, BaseColor>>> bugTable = new LinkedList<>();
for(Issue issue : issues) {
if(issue.getFixedInVersion().trim().equals(version.getTitle().trim())) {
ObjectPDF.addRowToTable(String.valueOf(issue.getId()), issue.getTitle(), false, bugTable);
}
}
pdfDocument.add(ObjectPDF.addTable(null, null, bugTable));
}

private static void saveElementToPDF(Object object, Document pdfDocument, Map<String, Font> fonts) throws Exception {
if(object instanceof Project) {
Project project = (Project) object;
Expand Down Expand Up @@ -244,7 +275,11 @@ private static PdfPTable addTable(List<String> headers, float[] headerWidth, Lis
table.addCell(cell);
}
} else {
table = new PdfPTable(cells.get(0).size());
if(cells.size()!=0) {
table = new PdfPTable(cells.get(0).size());
} else {
table = new PdfPTable(1);
}
}

for(List<Map.Entry<String, BaseColor>> row : cells) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.domjos.unitrackerlibrary.model.issues.CustomField;
import de.domjos.unitrackerlibrary.model.issues.Issue;
import de.domjos.unitrackerlibrary.model.projects.Project;
import de.domjos.unitrackerlibrary.model.projects.Version;

public final class TrackerPDF<T> extends AbstractTracker<T> {
private byte[] array, icon;
Expand All @@ -43,6 +44,11 @@ public TrackerPDF(IBugService<T> bugService, Type type, T pid, List<T> ids, Stri
this.icon = icon;
}

public void createChangeLog(Version version) throws Exception {
List<Issue> issues = (List<Issue>) ids;
ObjectPDF.createChangeLog(issues, path, array, icon, version);
}

@Override
public void doExport() throws Exception {
switch (this.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ public void deleteVersion(Long id, Long project_id) throws Exception {

@Override
public long getMaximumNumberOfIssues(Long project_id, IssueFilter filter) throws Exception {
SoapObject request = new SoapObject(super.soapPath, "mc_project_get_issue_headers");
request.addProperty("project_id", Integer.parseInt(String.valueOf(project_id)));
SoapObject request = new SoapObject(super.soapPath, "mc_filter_search_issue_headers");
request.addProperty("page_number", 1);
request.addProperty("per_page", -1);
Object object = this.executeAction(request, "mc_project_get_issue_headers", true);
SoapObject filterObject = new SoapObject(NAMESPACE, "FilterSearchData");
Vector<Integer> projects = new Vector<>();
projects.add(Integer.parseInt(String.valueOf(project_id)));
filterObject.addProperty("project_id", projects);
request.addProperty("filter", filterObject);
Object object = this.executeAction(request, "mc_filter_search_issue_headers", true);
object = this.getResult(object);
if (object instanceof Vector) {
Vector vector = (Vector) object;
Expand Down Expand Up @@ -255,14 +259,18 @@ public List<Issue<Long>> getIssues(Long pid, int page, int numberOfItems) throws
public List<Issue<Long>> getIssues(Long pid, int page, int numberOfItems, IssueFilter filter) throws Exception {
List<Issue<Long>> issues = new LinkedList<>();

SoapObject request = new SoapObject(super.soapPath, "mc_project_get_issue_headers");
request.addProperty("project_id", Integer.parseInt(String.valueOf(pid)));
SoapObject request = new SoapObject(super.soapPath, "mc_filter_search_issue_headers");
request.addProperty("page_number", page);
request.addProperty("per_page", numberOfItems);
SoapObject filterObject = new SoapObject(NAMESPACE, "FilterSearchData");
Vector<Integer> projects = new Vector<>();
projects.add(Integer.parseInt(String.valueOf(pid)));
filterObject.addProperty("project_id", projects);
request.addProperty("filter", filterObject);

List<String> enumView = this.getEnums("view_states");
List<String> enumStatus = this.getEnums("status");
Object object = this.executeAction(request, "mc_project_get_issue_headers", true);
Object object = this.executeAction(request, "mc_filter_search_issue_headers", true);
object = this.getResult(object);
if (object instanceof Vector) {
Vector vector = (Vector) object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,28 @@
import de.domjos.unitrackerlibrary.export.TrackerPDF;
import de.domjos.unitrackerlibrary.export.TrackerXML;
import de.domjos.unitrackerlibrary.interfaces.IBugService;
import de.domjos.unitrackerlibrary.model.issues.Issue;
import de.domjos.unitrackerlibrary.model.projects.Version;

public final class ExportTask extends AbstractTask<Object, Void, Void> {
private String path, xslt;
private TrackerXML.Type type;
private Object project_id;
private Object project_id, version_id;
private byte[] array, icon;

public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type type, Object project_id, String path, boolean showNotifications, int icon, byte[] array, byte[] appIcon, String xslt) {
this(activity, bugService, type, project_id, path, showNotifications, icon, array, appIcon, xslt, null);
}

public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type type, Object project_id, String path, boolean showNotifications, int icon, byte[] array, byte[] appIcon, String xslt, Object versionId) {
super(activity, bugService, R.string.task_export_title, R.string.task_export_contet, showNotifications, icon);
this.path = path;
this.type = type;
this.project_id = project_id;
this.array = array;
this.icon = appIcon;
this.xslt = xslt;
this.version_id = versionId;
}

@Override
Expand All @@ -54,24 +61,40 @@ protected void before() {
@SuppressWarnings("unchecked")
protected Void doInBackground(Object... objects) {
try {
String[] splPath = this.path.split("\\.");
String extension = splPath[splPath.length - 1];
List<Object> objectList = Arrays.asList(objects);
if(this.version_id == null) {
List<Object> objectList = Arrays.asList(objects);
String[] splPath = this.path.split("\\.");
String extension = splPath[splPath.length - 1];

switch (extension.trim().toLowerCase()) {
case "xml":
TrackerXML buggerXML = new TrackerXML(super.bugService, this.type, this.project_id, objectList, this.path, this.xslt);
buggerXML.doExport();
break;
case "txt":
case "csv":
TrackerCSV buggerCSV = new TrackerCSV(super.bugService, this.type, this.project_id, objectList, this.path);
buggerCSV.doExport();
break;
case "pdf":
TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path, this.array, this.icon);
buggerPDF.doExport();
break;
}
} else {
List<Issue> issues = super.bugService.getIssues(super.returnTemp(this.project_id));
for(int i = 0; i<=issues.size()-1; i++) {
issues.set(i, super.bugService.getIssue(issues.get(i).getId(), super.returnTemp(project_id)));
}

switch (extension.trim().toLowerCase()) {
case "xml":
TrackerXML buggerXML = new TrackerXML(super.bugService, this.type, this.project_id, objectList, this.path, this.xslt);
buggerXML.doExport();
break;
case "txt":
case "csv":
TrackerCSV buggerCSV = new TrackerCSV(super.bugService, this.type, this.project_id, objectList, this.path);
buggerCSV.doExport();
break;
case "pdf":
TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path, this.array, this.icon);
buggerPDF.doExport();
break;
List<Version> versions = super.bugService.getVersions("versions", super.returnTemp(this.project_id));
TrackerPDF<Issue> buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, issues, this.path, this.array, this.icon);
for(Version current : versions) {
if(current.getId().equals(this.version_id)) {
buggerPDF.createChangeLog(current);
break;
}
}
}
} catch (Exception ex) {
super.printException(ex);
Expand Down

0 comments on commit ced0183

Please sign in to comment.