mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-30 21:04:16 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="@dimen/padding_small"
|
||||
android:paddingBottom="@dimen/padding_small">
|
||||
<TextView android:id="@+id/fieldValue"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:scrollHorizontally="false"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="none"/>
|
||||
</TableRow>
|
|
@ -0,0 +1,12 @@
|
|||
package com.adins.mss.foundation.camerainapp.helper;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 6/21/2016.
|
||||
*/
|
||||
public interface BaseViewInterface<T> {
|
||||
|
||||
Context getContext();
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright 2013 Chris Banes
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package uk.co.senab.actionbarpulltorefresh.library;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import uk.co.senab.actionbarpulltorefresh.library.viewdelegates.AbsListViewDelegate;
|
||||
import uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ScrollYDelegate;
|
||||
import uk.co.senab.actionbarpulltorefresh.library.viewdelegates.ViewDelegate;
|
||||
import uk.co.senab.actionbarpulltorefresh.library.viewdelegates.WebViewDelegate;
|
||||
|
||||
class InstanceCreationUtils {
|
||||
|
||||
private static final String LOG_TAG = "InstanceCreationUtils";
|
||||
|
||||
private static final Class<?>[] VIEW_DELEGATE_CONSTRUCTOR_SIGNATURE = new Class[]{};
|
||||
private static final Class<?>[] TRANSFORMER_CONSTRUCTOR_SIGNATURE = new Class[]{};
|
||||
|
||||
private static final HashMap<Class, Class> BUILT_IN_DELEGATES;
|
||||
|
||||
static {
|
||||
BUILT_IN_DELEGATES = new HashMap<Class, Class>();
|
||||
addBuiltinDelegates(AbsListViewDelegate.SUPPORTED_VIEW_CLASSES, AbsListViewDelegate.class);
|
||||
addBuiltinDelegates(ScrollYDelegate.SUPPORTED_VIEW_CLASSES, ScrollYDelegate.class);
|
||||
addBuiltinDelegates(WebViewDelegate.SUPPORTED_VIEW_CLASSES, WebViewDelegate.class);
|
||||
}
|
||||
|
||||
private static void addBuiltinDelegates(Class[] supportedViews, Class<?> delegateClass) {
|
||||
for (int i = 0, z = supportedViews.length; i < z; i++) {
|
||||
BUILT_IN_DELEGATES.put(supportedViews[i], delegateClass);
|
||||
}
|
||||
}
|
||||
|
||||
static ViewDelegate getBuiltInViewDelegate(final View view) {
|
||||
final Set<Map.Entry<Class, Class>> entries = BUILT_IN_DELEGATES.entrySet();
|
||||
for (final Map.Entry<Class, Class> entry : entries) {
|
||||
if (entry.getKey().isInstance(view)) {
|
||||
return InstanceCreationUtils.newInstance(view.getContext(),
|
||||
entry.getValue(), VIEW_DELEGATE_CONSTRUCTOR_SIGNATURE);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static <T> T instantiateViewDelegate(Context context, String className) {
|
||||
try {
|
||||
Class<?> clazz = context.getClassLoader().loadClass(className);
|
||||
return newInstance(context, clazz, VIEW_DELEGATE_CONSTRUCTOR_SIGNATURE);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Log.w(LOG_TAG, "Cannot instantiate class: " + className, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static <T> T instantiateTransformer(Context context, String className) {
|
||||
try {
|
||||
Class<?> clazz = context.getClassLoader().loadClass(className);
|
||||
return newInstance(context, clazz, TRANSFORMER_CONSTRUCTOR_SIGNATURE);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Log.w(LOG_TAG, "Cannot instantiate class: " + className, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <T> T newInstance(Context context, Class clazz, Class[] constructorSig,
|
||||
Object... arguments) {
|
||||
try {
|
||||
Constructor<?> constructor = clazz.getConstructor(constructorSig);
|
||||
return (T) constructor.newInstance(arguments);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Log.w(LOG_TAG, "Cannot instantiate class: " + clazz.getName(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,486 @@
|
|||
package com.adins.mss.base.syncfile;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.MobileDataFile;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Created by loise on 10/13/2017.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class contining data to update dialog interface data
|
||||
*/
|
||||
class TaskProgress {
|
||||
final int percentage;
|
||||
final String message;
|
||||
final int max;
|
||||
|
||||
TaskProgress(int percentage, String message, int max) {
|
||||
this.percentage = percentage;
|
||||
this.message = message;
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Async task to download files
|
||||
*/
|
||||
public class FileDownloader extends AsyncTask<DownloadParams, TaskProgress, String> {
|
||||
|
||||
/**
|
||||
* Background Async Task to download file
|
||||
*/
|
||||
ProgressDialog dialog;
|
||||
// Progress Dialog
|
||||
private ProgressDialog pDialog;
|
||||
private WeakReference<Context> context;
|
||||
|
||||
public FileDownloader(Context mContext) {
|
||||
context = new WeakReference<>(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* method untuk mendapatkan link bila url menggunakan shortener
|
||||
*
|
||||
* @param link link awal
|
||||
* @return link hasil redirect
|
||||
*/
|
||||
private HttpURLConnection getRedirectedConnection(String link) {
|
||||
URL url = null;
|
||||
URL secondURL = null;
|
||||
HttpURLConnection connect = null;
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
url = new URL(link);
|
||||
connect = (HttpURLConnection) url.openConnection();
|
||||
connect.setConnectTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
connect.setInstanceFollowRedirects(false);
|
||||
secondURL = new URL(connect.getHeaderField("Location"));
|
||||
connection = (HttpURLConnection) secondURL.openConnection();
|
||||
connection.setConnectTimeout(Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
return connection;
|
||||
} catch (java.net.SocketTimeoutException e) {
|
||||
Log.e("Error ", e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//to check if file sha1 matches
|
||||
private Boolean checkIsBadFile(String message, String filepath, String sha1) {
|
||||
String info = message + " (File found!)";
|
||||
boolean isBadFile = false;
|
||||
TaskProgress progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
e.printStackTrace();
|
||||
}
|
||||
String savedSha1, newSha1;
|
||||
try {
|
||||
info = message + " (Checking file integrity...)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
File storedFile = new File(filepath);
|
||||
savedSha1 = FileSigner.getSha1String(storedFile);
|
||||
newSha1 = sha1;
|
||||
if (savedSha1.equals(newSha1)) {
|
||||
isBadFile = false;
|
||||
info = message + " (Success, File signature match!)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} else {
|
||||
isBadFile = true;
|
||||
boolean deleteResult = storedFile.delete();
|
||||
if(!deleteResult){
|
||||
Toast.makeText(context.get(), "Failed to delete stored file", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
info = message + " (File signature mismatch, deleting file...)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return isBadFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* untuk menampilkan progress dialog
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
protected ProgressDialog showDownloadDialog(Context context) {
|
||||
|
||||
pDialog = new ProgressDialog(context);
|
||||
pDialog.setMessage(context.getString(R.string.downloading_file));
|
||||
pDialog.setIndeterminate(false);
|
||||
pDialog.setMax(1);
|
||||
pDialog.setProgressNumberFormat("%1d KB/%2d KB");
|
||||
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
pDialog.setCancelable(false);
|
||||
pDialog.show();
|
||||
return pDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before starting background thread
|
||||
* Show Progress Bar Dialog
|
||||
*/
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
dialog = showDownloadDialog(FileSyncHelper.instance);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloading file in background thread
|
||||
*/
|
||||
@Override
|
||||
protected String doInBackground(DownloadParams... params) {
|
||||
//inisialisasi data
|
||||
int count;
|
||||
String link = "";
|
||||
String message = params[0].message;
|
||||
String info;
|
||||
String fileName = "";
|
||||
TaskProgress progress;
|
||||
//update progress
|
||||
Calendar cal = Calendar.getInstance();
|
||||
info = message + " (Checking storage...)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
MobileDataFile savedMetadata;
|
||||
MobileDataFile newMetadata;
|
||||
newMetadata = params[0].getMetadata();
|
||||
newMetadata.setDtm_crt(newMetadata.getDtm_crt());
|
||||
newMetadata.setDtm_upd(newMetadata.getDtm_upd());
|
||||
//wait supaya bisa dibaca messagenya
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
//cek apakah file ada di dalam storage
|
||||
boolean updated = false, fileExists = false, needDownloading = true;
|
||||
savedMetadata = MobileDataFileDataAccess.getOne(FileSyncHelper.instance, params[0].getMetadata().getId_datafile());
|
||||
if (savedMetadata != null) {
|
||||
//cek apakah ada update pada data dari server
|
||||
if (!savedMetadata.getIs_active().equals(newMetadata.getIs_active()) || !savedMetadata.getHash_sha1().equals(newMetadata.getHash_sha1())) {
|
||||
updated = true;
|
||||
}
|
||||
//cek apakah file didelete oleh user tetapi path tersimpan di db mobile
|
||||
if (savedMetadata.getDownloaded_file_path() != null && !savedMetadata.getDownloaded_file_path().isEmpty()) {
|
||||
fileExists = new File(savedMetadata.getDownloaded_file_path()).exists();
|
||||
}
|
||||
}
|
||||
//cek apabila file ada dan tidak ada perubahan dari server.
|
||||
if (fileExists && !updated) {
|
||||
//bila file sudah diimport maka skip file, jika belum diimport, cek integritas dan bila gagal download ulang
|
||||
if (savedMetadata.getImport_flag() == null || savedMetadata.getImport_flag() == true)
|
||||
needDownloading = checkIsBadFile(message, savedMetadata.getDownloaded_file_path(), newMetadata.getHash_sha1());
|
||||
else needDownloading = false;
|
||||
}
|
||||
//cek bila file sudah inactive, bila inactive maka file didelete dari storage
|
||||
else if (fileExists && params[0].getMetadata().getIs_active().equals("0")) {
|
||||
info = message + " (File inactive, deleting...)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
boolean deleteResult = new File(savedMetadata.getDownloaded_file_path()).delete();
|
||||
if(!deleteResult){
|
||||
Toast.makeText(context.get(), "Failed to delete file", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
needDownloading = false;
|
||||
}
|
||||
//skip download bila file inactive
|
||||
else if (!fileExists && params[0].getMetadata().getIs_active().equals("0")) {
|
||||
info = message + " (File inactive, skipping file...)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
needDownloading = false;
|
||||
}
|
||||
//proses download file
|
||||
if (needDownloading) {
|
||||
OutputStream output = null;
|
||||
try {
|
||||
//connect to url
|
||||
info = message + " (Connecting...)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
HttpURLConnection connection;
|
||||
connection = getRedirectedConnection(newMetadata.getFile_url());
|
||||
if (connection != null && connection.getResponseCode() == HttpURLConnection.HTTP_OK){
|
||||
link = connection.getURL().toString();
|
||||
String fieldValue = connection.getHeaderField("Content-Disposition");
|
||||
fieldValue = fieldValue.replace(" ", "");
|
||||
if (fieldValue == null || ! fieldValue.contains("filename=\"")) {
|
||||
fileName = link.substring(link.lastIndexOf("/"), link.length());
|
||||
}else{
|
||||
fileName = fieldValue.substring(fieldValue.indexOf("filename=\"") + 10, fieldValue.length() - 1);
|
||||
if(fileName.contains(";")){
|
||||
fileName = fileName.substring(0, fileName.indexOf(";")-1);
|
||||
}
|
||||
}
|
||||
connection.connect();
|
||||
// getting file length
|
||||
int lengthOfFile = connection.getContentLength();
|
||||
|
||||
// input stream to read file - with 8k buffer
|
||||
try(BufferedInputStream input = new BufferedInputStream(connection.getURL().openStream(), 8192)){
|
||||
//check and create dir
|
||||
File outputDir = new File(params[0].outputfilepath);
|
||||
if (!outputDir.exists()) outputDir.mkdirs();
|
||||
info = message + " (Connected!)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
// Output stream to write file
|
||||
File savedFile = new File(params[0].outputfilepath + fileName);
|
||||
Boolean signatureMatches = false;
|
||||
//cek jika file sudah ada tetapi tidak ada entry di database
|
||||
if (savedFile.exists()) {
|
||||
//bila file inactive delete file
|
||||
if (params[0].getMetadata().getIs_active().equals("0")) {
|
||||
boolean deleteResult = savedFile.delete();
|
||||
if(!deleteResult){
|
||||
Toast.makeText(context.get(), "Failed to delete file", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
info = message + " (File inactive, deleting...)";
|
||||
progress = new TaskProgress(1, info, 1);
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
needDownloading = false;
|
||||
} else {
|
||||
//bila file active cek integritas data
|
||||
signatureMatches = !checkIsBadFile(message, savedFile.getPath(), newMetadata.getHash_sha1());
|
||||
if (signatureMatches) {
|
||||
//bila data tidak rusak beri flag untul diimport ke database
|
||||
newMetadata.setDownloaded_file_path(savedFile.getPath());
|
||||
newMetadata.setImport_flag(true);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
needDownloading = false;
|
||||
} else {
|
||||
//bila data rusak maka coba download ulang
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
needDownloading = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//download file
|
||||
if (needDownloading && params[0].getMetadata().getIs_active().equals("1")) {
|
||||
String downloadPath = params[0].outputfilepath + fileName;
|
||||
output = new FileOutputStream(downloadPath);
|
||||
byte data[] = new byte[1024];
|
||||
long total = 0;
|
||||
info = message + " (Downloading...)";
|
||||
while ((count = input.read(data)) != -1) {
|
||||
total += count;
|
||||
// publishing the progress....
|
||||
// After this onProgressUpdate will be called
|
||||
progress = new TaskProgress((int) (total / 1024), info, (lengthOfFile / 1024));
|
||||
publishProgress(progress);
|
||||
// writing data to file
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
// flushing output
|
||||
output.flush();
|
||||
|
||||
boolean badFile;
|
||||
info = message + " (Download Success!)";
|
||||
progress = new TaskProgress((lengthOfFile / 1024), info, (lengthOfFile / 1024));
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(params[0].outputfilepath + fileName);
|
||||
newMetadata.setImport_flag(true);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
//cek integritas data yang didownload
|
||||
badFile = checkIsBadFile(message, downloadPath, newMetadata.getHash_sha1());
|
||||
if (badFile) {
|
||||
//jika file berubah SHA1 nya maka file didelete dan user mendapatkan notifikasi
|
||||
info = "file with id #" + params[0].getMetadata().getId_datafile() + " is corrupted, please contact your administrator";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
Thread.sleep(1000);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
}
|
||||
}
|
||||
//jika file ditemukan dan belum di import
|
||||
else if (!needDownloading && params[0].getMetadata().getIs_active().equals("1")) {
|
||||
info = message + " (Success, file already downloaded.)";
|
||||
progress = new TaskProgress(1, info, 1);
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(savedFile.getPath());
|
||||
newMetadata.setImport_flag(true);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
}
|
||||
//jika file inactive maka proses download di skip
|
||||
else {
|
||||
info = message + " (Success, skipped download, file not needed.)";
|
||||
progress = new TaskProgress(1, info, 1);
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
}
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
info = message + " (ERROR : File not found! Please contact administrator)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
Log.e("Error: ", e.getMessage());
|
||||
} catch (MalformedURLException e) {
|
||||
info = message + " (ERROR : Bad Url!)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
Log.e("Error: ", e.getMessage());
|
||||
} catch (IOException e) {
|
||||
info = message + " (ERROR : Failed to save file!)";
|
||||
progress = new TaskProgress(0, info, 1);
|
||||
publishProgress(progress);
|
||||
Log.e("Error: ", e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
// closing streams
|
||||
if(output != null)
|
||||
output.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if (!fileExists && params[0].getMetadata().getIs_active().equals("0")) {
|
||||
info = message + " (File inactive, skipping file...)";
|
||||
progress = new TaskProgress((1), info, (1));
|
||||
publishProgress(progress);
|
||||
newMetadata.setDownloaded_file_path(null);
|
||||
newMetadata.setImport_flag(false);
|
||||
MobileDataFileDataAccess.addOrReplace(FileSyncHelper.instance, newMetadata);
|
||||
} else {
|
||||
info = message + " (Success, file already downloaded.)";
|
||||
progress = new TaskProgress(1, info, 1);
|
||||
publishProgress(progress);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updating progress bar
|
||||
*/
|
||||
@Override
|
||||
protected void onProgressUpdate(TaskProgress... progress) {
|
||||
// setting progress progress
|
||||
pDialog.setProgress(progress[0].percentage);
|
||||
pDialog.setMessage(progress[0].message);
|
||||
pDialog.setMax(progress[0].max);
|
||||
}
|
||||
|
||||
/**
|
||||
* After completing background task
|
||||
* Dismiss the progress dialog
|
||||
**/
|
||||
@Override
|
||||
protected void onPostExecute(String string) {
|
||||
Message msg;
|
||||
Bundle bundle;
|
||||
// dismiss the dialog after the file was downloaded
|
||||
if (dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
//panggil download kembali bila masih ada file yang butuh di download
|
||||
if (FileSyncHelper.currentidx < FileSyncHelper.getData().size() - 1) {
|
||||
if(FileSyncHelper.instance==null){
|
||||
FileSyncHelper.instance = context.get();
|
||||
}
|
||||
FileSyncHelper.downloadFiles();
|
||||
}
|
||||
//mulai proses import bila semua file dari server sudah di cek
|
||||
else {
|
||||
FileSyncHelper.currentidx = -1;
|
||||
FileSyncHelper.activeData = MobileDataFileDataAccess.getAllActive(FileSyncHelper.instance);
|
||||
if (!FileSyncHelper.activeData.isEmpty()) {
|
||||
if(FileSyncHelper.instance == null)
|
||||
FileSyncHelper.instance = context.get();
|
||||
FileSyncHelper.importFiles();
|
||||
}
|
||||
//bila tidak ada file yang butuh diimport maka proses import di skip
|
||||
else {
|
||||
if (FileSyncHelper.instance == null) {
|
||||
FileSyncHelper.instance = context.get();
|
||||
}
|
||||
Toast.makeText(FileSyncHelper.instance, FileSyncHelper.instance.getResources().getString(R.string.database_is_uptodate), Toast.LENGTH_SHORT).show();
|
||||
FileSyncHelper.synchronizeCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.adins.mss.foundation.db.dataaccess;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.DaoSession;
|
||||
import com.adins.mss.dao.Product;
|
||||
import com.adins.mss.dao.ProductDao;
|
||||
import com.adins.mss.foundation.db.DaoOpenHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 11/16/2017.
|
||||
*/
|
||||
|
||||
public class ProductDataAccess {
|
||||
|
||||
protected static DaoSession getDaoSession(Context context) {
|
||||
return DaoOpenHelper.getDaoSession(context);
|
||||
}
|
||||
|
||||
protected static ProductDao getProductDao(Context context) {
|
||||
return getDaoSession(context).getProductDao();
|
||||
}
|
||||
|
||||
public static void add(Context context, Product product) {
|
||||
getProductDao(context).insert(product);
|
||||
getDaoSession(context).clear();
|
||||
}
|
||||
|
||||
public static void add(Context context, List<Product> productList) {
|
||||
getProductDao(context).insertInTx(productList);
|
||||
getDaoSession(context).clear();
|
||||
}
|
||||
|
||||
public static void addOrReplace(Context context, Product product) {
|
||||
getProductDao(context).insertOrReplaceInTx(product);
|
||||
getDaoSession(context).clear();
|
||||
}
|
||||
|
||||
public static void addOrReplace(Context context, List<Product> productList) {
|
||||
getProductDao(context).insertOrReplaceInTx(productList);
|
||||
getDaoSession(context).clear();
|
||||
}
|
||||
|
||||
public static void clean(Context context) {
|
||||
getProductDao(context).deleteAll();
|
||||
}
|
||||
|
||||
public static void delete(Context context, Product product) {
|
||||
getProductDao(context).delete(product);
|
||||
getDaoSession(context).clear();
|
||||
}
|
||||
|
||||
public static void update(Context context, Product product) {
|
||||
getProductDao(context).update(product);
|
||||
}
|
||||
|
||||
public static List<Product> getAll(Context context) {
|
||||
QueryBuilder<Product> qb = getProductDao(context).queryBuilder();
|
||||
qb.build();
|
||||
return qb.list();
|
||||
}
|
||||
|
||||
public static Product getOne(Context context, String uuid) {
|
||||
QueryBuilder<Product> qb = getProductDao(context).queryBuilder();
|
||||
qb.where(ProductDao.Properties.Uuid_product.eq(uuid));
|
||||
qb.build();
|
||||
|
||||
if ((qb.list() == null) || qb.list().isEmpty()) return null;
|
||||
return qb.list().get(0);
|
||||
}
|
||||
|
||||
public static Product getOneByCode(Context context, String productCode) {
|
||||
QueryBuilder<Product> qb = getProductDao(context).queryBuilder();
|
||||
qb.where(ProductDao.Properties.Product_code.eq(productCode));
|
||||
qb.build();
|
||||
|
||||
if ((qb.list() == null) || qb.list().isEmpty()) return null;
|
||||
return qb.list().get(0);
|
||||
}
|
||||
|
||||
public static List<Product> getAllByIsActive(Context context) {
|
||||
List<Product> list = null;
|
||||
QueryBuilder<Product> qb = getProductDao(context).queryBuilder();
|
||||
qb.where(ProductDao.Properties.Is_active.eq(Global.TRUE_STRING));
|
||||
qb.build();
|
||||
|
||||
if (qb != null) {
|
||||
list = qb.list();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.adins.libs.nineoldandroids.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Internal class to automatically generate a Property for a given class/name pair, given the
|
||||
* specification of {@link Property#of(java.lang.Class, java.lang.Class, java.lang.String)}
|
||||
*/
|
||||
class ReflectiveProperty<T, V> extends Property<T, V> {
|
||||
|
||||
private static final String PREFIX_GET = "get";
|
||||
private static final String PREFIX_IS = "is";
|
||||
private static final String PREFIX_SET = "set";
|
||||
private Method mSetter;
|
||||
private Method mGetter;
|
||||
private Field mField;
|
||||
|
||||
/**
|
||||
* For given property name 'name', look for getName/isName method or 'name' field.
|
||||
* Also look for setName method (optional - could be readonly). Failing method getters and
|
||||
* field results in throwing NoSuchPropertyException.
|
||||
*
|
||||
* @param propertyHolder The class on which the methods or field are found
|
||||
* @param name The name of the property, where this name is capitalized and appended to
|
||||
* "get" and "is to search for the appropriate methods. If the get/is methods are not found,
|
||||
* the constructor will search for a field with that exact name.
|
||||
*/
|
||||
public ReflectiveProperty(Class<T> propertyHolder, Class<V> valueType, String name) {
|
||||
// TODO: cache reflection info for each new class/name pair
|
||||
super(valueType, name);
|
||||
char firstLetter = Character.toUpperCase(name.charAt(0));
|
||||
String theRest = name.substring(1);
|
||||
String capitalizedName = firstLetter + theRest;
|
||||
String getterName = PREFIX_GET + capitalizedName;
|
||||
try {
|
||||
mGetter = propertyHolder.getMethod(getterName, (Class<?>[]) null);
|
||||
} catch (NoSuchMethodException e) {
|
||||
try {
|
||||
/* The native implementation uses JNI to do reflection, which allows access to private methods.
|
||||
* getDeclaredMethod(..) does not find superclass methods, so it's implemented as a fallback.
|
||||
*/
|
||||
mGetter = propertyHolder.getDeclaredMethod(getterName, (Class<?>[]) null);
|
||||
mGetter.setAccessible(true);
|
||||
} catch (NoSuchMethodException e2) {
|
||||
// getName() not available - try isName() instead
|
||||
getterName = PREFIX_IS + capitalizedName;
|
||||
try {
|
||||
mGetter = propertyHolder.getMethod(getterName, (Class<?>[]) null);
|
||||
} catch (NoSuchMethodException e3) {
|
||||
try {
|
||||
/* The native implementation uses JNI to do reflection, which allows access to private methods.
|
||||
* getDeclaredMethod(..) does not find superclass methods, so it's implemented as a fallback.
|
||||
*/
|
||||
mGetter = propertyHolder.getDeclaredMethod(getterName, (Class<?>[]) null);
|
||||
mGetter.setAccessible(true);
|
||||
} catch (NoSuchMethodException e4) {
|
||||
// Try public field instead
|
||||
try {
|
||||
mField = propertyHolder.getField(name);
|
||||
Class fieldType = mField.getType();
|
||||
if (!typesMatch(valueType, fieldType)) {
|
||||
throw new NoSuchPropertyException("Underlying type (" + fieldType + ") " +
|
||||
"does not match Property type (" + valueType + ")");
|
||||
}
|
||||
return;
|
||||
} catch (NoSuchFieldException e5) {
|
||||
// no way to access property - throw appropriate exception
|
||||
throw new NoSuchPropertyException("No accessor method or field found for"
|
||||
+ " property with name " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Class getterType = mGetter.getReturnType();
|
||||
// Check to make sure our getter type matches our valueType
|
||||
if (!typesMatch(valueType, getterType)) {
|
||||
throw new NoSuchPropertyException("Underlying type (" + getterType + ") " +
|
||||
"does not match Property type (" + valueType + ")");
|
||||
}
|
||||
String setterName = PREFIX_SET + capitalizedName;
|
||||
try {
|
||||
// mSetter = propertyHolder.getMethod(setterName, getterType);
|
||||
// The native implementation uses JNI to do reflection, which allows access to private methods.
|
||||
mSetter = propertyHolder.getDeclaredMethod(setterName, getterType);
|
||||
mSetter.setAccessible(true);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
// Okay to not have a setter - just a readonly property
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to check whether the type of the underlying field/method on the target
|
||||
* object matches the type of the Property. The extra checks for primitive types are because
|
||||
* generics will force the Property type to be a class, whereas the type of the underlying
|
||||
* method/field will probably be a primitive type instead. Accept float as matching Float,
|
||||
* etc.
|
||||
*/
|
||||
private boolean typesMatch(Class<V> valueType, Class getterType) {
|
||||
if (getterType != valueType) {
|
||||
if (getterType.isPrimitive()) {
|
||||
return (getterType == float.class && valueType == Float.class) ||
|
||||
(getterType == int.class && valueType == Integer.class) ||
|
||||
(getterType == boolean.class && valueType == Boolean.class) ||
|
||||
(getterType == long.class && valueType == Long.class) ||
|
||||
(getterType == double.class && valueType == Double.class) ||
|
||||
(getterType == short.class && valueType == Short.class) ||
|
||||
(getterType == byte.class && valueType == Byte.class) ||
|
||||
(getterType == char.class && valueType == Character.class);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(T object, V value) {
|
||||
if (mSetter != null) {
|
||||
try {
|
||||
mSetter.invoke(object, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new AssertionError();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e.getCause());
|
||||
}
|
||||
} else if (mField != null) {
|
||||
try {
|
||||
mField.set(object, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Property " + getName() + " is read-only");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(T object) {
|
||||
if (mGetter != null) {
|
||||
try {
|
||||
return (V) mGetter.invoke(object, (Object[]) null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new AssertionError();
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e.getCause());
|
||||
}
|
||||
} else if (mField != null) {
|
||||
try {
|
||||
return (V) mField.get(object);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
// Should not get here: there should always be a non-null getter or field
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if there is no setter or public field underlying this Property.
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return (mSetter == null && mField == null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.adins.mss.coll.closingtask;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.adins.mss.coll.closingtask.models.ClosingTaskEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 6/6/2016.
|
||||
*/
|
||||
public class ClosingTaskAdapter extends BaseAdapter {
|
||||
private static ClosingTaskAdapter instance;
|
||||
private List<ClosingTaskEntity> entities;
|
||||
|
||||
public ClosingTaskAdapter() {
|
||||
|
||||
}
|
||||
|
||||
public static ClosingTaskAdapter getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ClosingTaskAdapter();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (entities == null) return 0;
|
||||
|
||||
return entities.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClosingTaskEntity getItem(int position) {
|
||||
if (entities == null) return null;
|
||||
|
||||
return entities.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ClosingTaskItem item;
|
||||
|
||||
if (convertView == null) {
|
||||
item = new ClosingTaskItem(parent.getContext());
|
||||
} else {
|
||||
item = (ClosingTaskItem) convertView;
|
||||
}
|
||||
|
||||
item.bind(getItem(position));
|
||||
return item;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (entities != null) {
|
||||
entities.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void processData(List<ClosingTaskEntity> ts) {
|
||||
if (ts == null || ts.size() <= 0) return;
|
||||
|
||||
if (entities == null) {
|
||||
entities = ts;
|
||||
} else {
|
||||
entities.addAll(ts);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void releaseResources() {
|
||||
clear();
|
||||
notifyDataSetChanged();
|
||||
|
||||
entities = null;
|
||||
instance = null;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
Loading…
Add table
Add a link
Reference in a new issue