Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build when come from fork and other issues #29

Merged
merged 3 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ android {
}
buildTypes {
buildTypes.each {
it.buildConfigField 'String', 'GLPI_USER', glpi_user
it.buildConfigField 'String', 'GLPI_PASSWORD', glpi_password
it.buildConfigField 'String', 'GLPI_URL', glpi_url
def glpi_user_val = glpi_user ?: "\"\""
def glpi_password_val = glpi_password ?: "\"\""
def glpi_url_val = glpi_url ?: "\"\""

it.buildConfigField 'String', 'GLPI_USER', glpi_user_val
it.buildConfigField 'String', 'GLPI_PASSWORD', glpi_password_val
it.buildConfigField 'String', 'GLPI_URL', glpi_url_val
}
release {
minifyEnabled false
Expand All @@ -33,4 +37,5 @@ dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':glpi')
compile 'com.orhanobut:logger:2.1.0'
}
225 changes: 225 additions & 0 deletions app/src/main/java/org/glpi/glpiproject/FlyveLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of the GLPI API Client Library for Java,
* a subproject of GLPI. GLPI is a free IT Asset Management.
*
* GLPI 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.
*
* GLPI 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.
* --------------------------------------------------------------------
* @author Rafael Hernandez - <[email protected]>
* @copyright (C) 2017 Teclib' and contributors.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/glpi-project/java-library-glpi
* @link http://www.glpi-project.org/
* --------------------------------------------------------------------
*/

package org.glpi.glpiproject;

import android.os.Environment;
import com.orhanobut.logger.Logger;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
* This is a Log wrapper
*/
public class FlyveLog {

private static final String FILE_NAME_FEEDBACK = "FlyveMDMFeedback.txt";
public static final String FILE_NAME_LOG = "FlyveMDMLog.txt";

/**
* private constructor to prevent instances of this class
*/
private FlyveLog() {
}

/**
* Send a DEBUG log message
* @param object Object to write
*/
public static void d(Object object) {
Logger.d(object);
}

/**
* Send a DEBUG log message
* @param message String message to log
* @param args Objects
*/
public static void d(String message, Object... args) {
// do something for a debug build
Logger.d(message,args);

}

/**
* Send a VERBOSE log message
* @param message String message
* @param args Objects
*/
public static void v(String message, Object... args) {
Logger.v(message, args);
}

/**
* Send INFORMATION log message
* @param message String message
* @param args Objects
*/
public static void i(String message, Object... args) {
Logger.i(message, args);
}

/**
* Send ERROR log message
* @param throwable Throwable error
* @param message String message
* @param args Objects
*/
public static void e(Throwable throwable, String message, Object... args) {
Logger.e(throwable, message, args);
}

/**
* Send Error log message
* @param message String message
* @param args Objects
*/
public static void e(String message, Object... args) {
Logger.e(message, args);
}

/**
* send What a Terrible Failure log message
* @param message String message
* @param args Objects
*/
public static void wtf(String message, Object... args) {
Logger.wtf(message, args);
}

/**
* Send a JSON log message
* @param json String the json to show
*/
public static void json(String json) {
Logger.json(json);
}

/**
* Send a XML log message
* @param xml String the xml to show
*/
public static void xml(String xml) {
Logger.xml(xml);
}

/**
* Logs the message in a directory
* @param string the message
* @param string the filename
*/
public static void f(String message, String filename) {
String state = Environment.getExternalStorageState();

File dir = new File("/sdcard/FlyveMDM");
if (Environment.MEDIA_MOUNTED.equals(state)) {
if(!dir.exists()) {
FlyveLog.d("Dir created ", "Dir created ");
dir.mkdirs();
}

File logFile = new File("/sdcard/FlyveMDM/" + filename);

if (!logFile.exists()) {
try {
FlyveLog.d("File created ", "File created ");
logFile.createNewFile();
} catch (IOException ex) {
FlyveLog.e(ex.getMessage());
}
}

FileWriter fw = null;
try {
//BufferedWriter for performance, true to set append to file flag
fw = new FileWriter(logFile, true);
BufferedWriter buf = new BufferedWriter(fw);

buf.write(message);
buf.newLine();
buf.flush();
buf.close();
fw.close();
}
catch (IOException ex) {
e(ex.getMessage());
}
finally {
if(fw!=null) {
try {
fw.close();
} catch(Exception ex) {
FlyveLog.e(ex.getMessage());
}
}
}
}
}

/**
* Clear the log
* @param string the file name
* @throws Exception an error message
*/
public static void clearLog(String filename) {
String state = Environment.getExternalStorageState();

File dir = new File("/sdcard/FlyveMDM");
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (!dir.exists()) {
FlyveLog.d("Dir created ", "Dir created ");
dir.mkdirs();
}

File logFile = new File("/sdcard/FlyveMDM/" + filename);

FileWriter fw = null;
try {
//BufferedWriter for performance, true to set append to file flag
fw = new FileWriter(logFile, false);
PrintWriter pwOb = new PrintWriter(fw, false);
pwOb.flush();
pwOb.close();
}
catch (IOException ex) {
e(ex.getMessage());
}
finally {
if(fw!=null) {
try {
fw.close();
} catch(Exception ex) {
FlyveLog.e(ex.getMessage());
}
}
}

}
}

}
Loading