Merge pull request #54 from CPM-INDIA-SALES-AND-MARKETING-PVT-LTD/ysy_previous_image_5days_upload

previous image upload
This commit is contained in:
YadavendraSinghYaduvanshi
2018-04-08 23:25:48 +05:30
committed by GitHub
6 changed files with 153 additions and 46 deletions
+23
View File
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="mavenHome" value="Bundled (Maven 3)" />
</MavenGeneralSettings>
</option>
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
@@ -30,4 +37,20 @@
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
Generated
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+4 -4
View File
@@ -25,13 +25,13 @@ android {
versionName "2.6"*/
//For KSA
/* versionCode 12
versionName "2.5"*/
versionCode 12
versionName "2.5"
//For Turkey
versionCode 11
/*versionCode 11
versionName "2.4"
*/
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -5,7 +5,6 @@ import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ClipData;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -31,6 +30,8 @@ import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.Trace;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
@@ -44,21 +45,25 @@ import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import cpm.com.gskmtorange.autoupdate.AutoUpdateActivity;
import cpm.com.gskmtorange.constant.CommonFunctions;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.upload.UploadImageWithRetrofit;
import cpm.com.gskmtorange.xmlGetterSetter.FailureGetterSetter;
import cpm.com.gskmtorange.xmlGetterSetter.LoginGetterSetter;
import cpm.com.gskmtorange.xmlHandlers.XMLHandlers;
import io.fabric.sdk.android.Fabric;
import static android.Manifest.permission.READ_CONTACTS;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.Trace;
/**
* A login screen that offers login via userid/password.
*/
@@ -185,6 +190,10 @@ public class LoginActivity extends AppCompatActivity {
if (!file.isDirectory()) {
file.mkdir();
}
File fileold = new File(Environment.getExternalStorageDirectory(), "GSK_MT_ORANGE_IMAGES");
if (!fileold.isDirectory()) {
fileold.mkdir();
}
}
@@ -655,11 +664,14 @@ public class LoginActivity extends AppCompatActivity {
CommonFunctions.updateLangResources(getApplicationContext(), preferences.getString(CommonString.KEY_LANGUAGE, ""));
Intent intent = new Intent(getBaseContext(),
/*Intent intent = new Intent(getBaseContext(),
MainActivity.class);
startActivity(intent);
finish();
finish();*/
uploadPreviousImages();
}
@@ -736,5 +748,75 @@ public class LoginActivity extends AppCompatActivity {
return cdate;
}
public void uploadPreviousImages(){
try {
File f = new File(CommonString.FILE_PATH_OLD);
if(f!=null){
File file[] = f.listFiles();
if(file!=null){
String newPattern = "EEE MMM dd HH:mm:ss Z yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(newPattern, Locale.ENGLISH);
Date c = Calendar.getInstance().getTime();
System.out.println("Current time => " + c);
//SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String formattedDate = sdf.format(c);
Date visitdate = sdf.parse(formattedDate);
for (int i=0;i<file.length;i++){
Date lastModDate = new Date(file[i].lastModified());
String day = lastModDate.toString();
//String day = "Sun Apr 01 22:20:48 GMT+05:30 2018";
Date file_date = sdf.parse(day);
long diff = visitdate.getTime() - file_date.getTime();
System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
long difference = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
if(difference>6){
file[i].delete();
}
/*SimpleDateFormat spf= new SimpleDateFormat("MM/dd/yyyy");
date = spf.format(newDate);
System.out.println(date);*/
}
if(file.length>0){
UploadImageWithRetrofit.uploadedFiles = 0;
UploadImageWithRetrofit.totalFiles = file.length;
UploadImageWithRetrofit uploadImg = new UploadImageWithRetrofit( LoginActivity.this);
uploadImg.UploadImageRecursive(LoginActivity.this);
}
else {
sendToMain();
}
}
else {
sendToMain();
}
}
else {
sendToMain();
}
} catch (ParseException e) {
e.printStackTrace();
sendToMain();
}
}
public void sendToMain(){
Intent intent = new Intent(getBaseContext(),
MainActivity.class);
startActivity(intent);
finish();
}
}
@@ -2,10 +2,9 @@ package cpm.com.gskmtorange;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Window;
import android.view.animation.Animation;
@@ -13,15 +12,11 @@ import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.upload.UploadImageWithRetrofit;
public class SplashScreenActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
@@ -42,32 +37,39 @@ public class SplashScreenActivity extends AppCompatActivity {
StartAnimations();
File f = new File(CommonString.FILE_PATH_OLD);
sendToLogin();
/* File f = new File(CommonString.FILE_PATH_OLD);
if(f!=null){
File file[] = f.listFiles();
if(file!=null){
for (int i=0;i<file.length;i++){
Date lastModDate = new Date(file[0].lastModified());
String day = lastModDate.toString();
for (int i=0;i<file.length;i++){
Date lastModDate = new Date(file[0].lastModified());
String day = lastModDate.toString();
/*SimpleDateFormat spf= new SimpleDateFormat("MM/dd/yyyy");
*//*SimpleDateFormat spf= new SimpleDateFormat("MM/dd/yyyy");
date = spf.format(newDate);
System.out.println(date);*/
}
if(file.length>0){
UploadImageWithRetrofit.uploadedFiles = 0;
UploadImageWithRetrofit.totalFiles = file.length;
UploadImageWithRetrofit uploadImg = new UploadImageWithRetrofit( SplashScreenActivity.this);
uploadImg.UploadImageRecursive(SplashScreenActivity.this);
}
else {
System.out.println(date);*//*
}
*//* if(file.length>0){
UploadImageWithRetrofit.uploadedFiles = 0;
UploadImageWithRetrofit.totalFiles = file.length;
UploadImageWithRetrofit uploadImg = new UploadImageWithRetrofit( SplashScreenActivity.this);
uploadImg.UploadImageRecursive(SplashScreenActivity.this);
}
else {
sendToLogin();
}*//*
}else {
sendToLogin();
}
}
else {
sendToLogin();
}
*/
}
private void StartAnimations() {
@@ -24,10 +24,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import cpm.com.gskmtorange.LoginActivity;
import cpm.com.gskmtorange.MainActivity;
import cpm.com.gskmtorange.R;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.retrofit.PostApiForFile;
@@ -140,7 +139,7 @@ public class UploadImageWithRetrofit {
if (status == 0) {
pd.dismiss();
if (!((Activity) context).isFinishing()) {
showAlert((Activity) context, "Image not uploaded");
showAlert((Activity) context, context.getString(R.string.DataNot),false);
}
} else {
UploadImageRecursive(context);
@@ -155,9 +154,7 @@ public class UploadImageWithRetrofit {
pd.dismiss();
// AlertandMessages.showAlert((Activity) context, "Network Error in upload", false);
if (!((Activity) context).isFinishing()) {
showAlert((Activity) context, "Network Error in upload");
} else {
showAlert((Activity) context, context.getString(R.string.NetworkError),false);
}
}
}
@@ -170,19 +167,19 @@ public class UploadImageWithRetrofit {
//new StatusUpload().execute();
//endregion
pd.cancel();
showAlert((Activity) context, context.getString(R.string.data_uploaded_successfully));
showAlert((Activity) context, context.getString(R.string.data_uploaded_successfully),true);
}
}
} catch (JsonSyntaxException e) {
e.printStackTrace();
showAlert((Activity) context, "Invalid Json");
showAlert((Activity) context, "Invalid Json",false);
} catch (Exception e) {
e.printStackTrace();
if (totalFiles == uploadedFiles) {
showAlert((Activity) context, "All images uploaded");
showAlert((Activity) context, context.getString(R.string.data_uploaded_successfully),true);
} else {
showAlert((Activity) context, CommonString.KEY_FAILURE);
showAlert((Activity) context, CommonString.KEY_FAILURE,false);
}
}
@@ -234,7 +231,7 @@ public class UploadImageWithRetrofit {
return file2;
}
public void showAlert(final Context context, String str) {
public void showAlert(final Context context, String str, final boolean flag) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Parinaam");
@@ -242,9 +239,12 @@ public class UploadImageWithRetrofit {
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Activity activity =(Activity) context;
Intent i = new Intent(activity, LoginActivity.class);
activity.startActivity(i);
activity.finish();
if(flag){
Intent i = new Intent(activity, MainActivity.class);
activity.startActivity(i);
activity.finish();
}
}
});