Skip to content

Commit

Permalink
update rest
Browse files Browse the repository at this point in the history
  • Loading branch information
domjos1994 committed Oct 10, 2019
1 parent 6f4105a commit d281d00
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 82 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dependencies {
// test libraries
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation project(path: ':unitrackerlibrary')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,4 @@ public class Helper {
static Context getContext() {
return InstrumentationRegistry.getInstrumentation().getTargetContext();
}

public static Authentication getAuthFromRes(int rawID, String bt) throws Exception {
Properties properties = Helper.readPropertiesFromRaw(rawID, Helper.getContext());
return new Authentication(properties.getProperty(bt + "_server"), properties.getProperty(bt + "_api"), properties.getProperty(bt + "_user"), properties.getProperty(bt + "_pwd"));
}

private static Properties readPropertiesFromRaw(int rawID, Context context) throws Exception {
Properties properties = new Properties();
Resources res = context.getResources();
InputStream in_s = res.openRawResource(rawID);
properties.load(in_s);
return properties;
}

public static int getVersionCode(Context context) throws Exception {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return info.versionCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.widget.Spinner;

import androidx.annotation.NonNull;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import com.github.angads25.filepicker.model.DialogConfigs;
import com.github.angads25.filepicker.model.DialogProperties;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void onNothingSelected(AdapterView<?> parent) {
String file = this.txtExportPath.getText().toString() + "." + this.spExportPath.getSelectedItem().toString();

if (bugService != null && project != null) {
ExportTask exportTask = new ExportTask(ExportActivity.this, bugService, type, project.getId(), file, notify, R.drawable.ic_import_export_black_24dp);
ExportTask exportTask = new ExportTask(ExportActivity.this, bugService, type, project.getId(), file, notify, R.drawable.ic_import_export_black_24dp, VectorDrawableCompat.create(this.getResources(), R.drawable.background, null));
List<Object> objects = new LinkedList<>();
switch (type) {
case Projects:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import de.domjos.unitrackermobile.R;

Expand All @@ -49,7 +51,7 @@ public abstract class SwipeToDeleteCallback extends ItemTouchHelper.Callback {
backgroundColor = Color.parseColor("#b80f0a");
mClearPaint = new Paint();
mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
deleteDrawable = ContextCompat.getDrawable(context, R.drawable.ic_delete_black_24dp);
deleteDrawable = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_delete_black_24dp, null);
assert deleteDrawable != null;
intrinsicWidth = deleteDrawable.getIntrinsicWidth();
intrinsicHeight = deleteDrawable.getIntrinsicHeight();
Expand Down
55 changes: 0 additions & 55 deletions app/src/main/java/de/domjos/unitrackermobile/helper/AdHelper.java

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
~ along with UniTrackerMobile. If not, see <http://www.gnu.org/licenses/>.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/list_background"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

package de.domjos.unitrackerlibrary.export;

import android.graphics.drawable.Drawable;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
Expand All @@ -47,19 +50,23 @@
import de.domjos.unitrackerlibrary.model.issues.Note;
import de.domjos.unitrackerlibrary.model.projects.Project;
import de.domjos.unitrackerlibrary.model.projects.Version;
import de.domjos.unitrackerlibrary.utils.Converter;

final class ObjectPDF {
private static final String H1 = "H1", H2 = "H2", H3 = "H3", BODY = "Body";


static void saveObjectToPDF(List lst, String path) throws Exception {
static void saveObjectToPDF(List lst, String path, Drawable drawable) 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();
if(drawable!=null) {
ObjectPDF.addBackground(drawable, pdfDocument);
}
PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(path));
writer.setBoxSize("art", new Rectangle(55, 25, 550, 788));
writer.setPageEvent(new Footer(lst.size()));
Expand All @@ -72,6 +79,12 @@ static void saveObjectToPDF(List lst, String path) throws Exception {
pdfDocument.close();
}

private static void addBackground(Drawable drawable, Document document) throws Exception {
Image image = Image.getInstance(Converter.convertDrawableToByteArray(drawable));
image.setAbsolutePosition(0, 0);
document.add(image);
}

private static void saveElementToPDF(Object object, Document pdfDocument, Map<String, Font> fonts) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
if(object instanceof Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package de.domjos.unitrackerlibrary.export;

import android.graphics.drawable.Drawable;
import android.util.Log;

import java.util.LinkedList;
Expand All @@ -29,10 +30,16 @@
import de.domjos.unitrackerlibrary.model.projects.Project;

public final class TrackerPDF<T> extends AbstractTracker<T> {

private Drawable drawable;

public TrackerPDF(IBugService<T> bugService, Type type, T pid, List<T> ids, String path) {
super(bugService, type, pid, ids, path);
this.drawable = null;
}

public TrackerPDF(IBugService<T> bugService, Type type, T pid, List<T> ids, String path, Drawable drawable) {
super(bugService, type, pid, ids, path);
this.drawable = drawable;
}

@Override
Expand All @@ -43,21 +50,21 @@ public void doExport() throws Exception {
for (T id : this.ids) {
projects.add(this.bugService.getProject(id));
}
ObjectPDF.saveObjectToPDF(projects, this.path);
ObjectPDF.saveObjectToPDF(projects, this.path, this.drawable);
break;
case Issues:
List<Issue> issues = new LinkedList<>();
for (T id : this.ids) {
issues.add(this.bugService.getIssue(id, this.pid));
}
ObjectPDF.saveObjectToPDF(issues, this.path);
ObjectPDF.saveObjectToPDF(issues, this.path, this.drawable);
break;
case CustomFields:
List<CustomField> customFields = new LinkedList<>();
for (T id : this.ids) {
customFields.add(this.bugService.getCustomField(id, this.pid));
}
ObjectPDF.saveObjectToPDF(customFields, this.path);
ObjectPDF.saveObjectToPDF(customFields, this.path, this.drawable);
break;
default:
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package de.domjos.unitrackerlibrary.tasks;

import android.app.Activity;
import android.graphics.drawable.Drawable;

import java.util.Arrays;
import java.util.List;
Expand All @@ -33,12 +34,18 @@ public final class ExportTask extends AbstractTask<Object, Void, Void> {
private String path;
private TrackerXML.Type type;
private Object project_id;
private Drawable drawable;

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

public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type type, Object project_id, String path, boolean showNotifications, int icon, Drawable drawable) {
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.drawable = drawable;
}

@Override
Expand All @@ -65,7 +72,7 @@ protected Void doInBackground(Object... objects) {
buggerCSV.doExport();
break;
case "pdf":
TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path);
TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path, this.drawable);
buggerPDF.doExport();
break;
}
Expand Down

0 comments on commit d281d00

Please sign in to comment.