Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
makbn committed Mar 8, 2018
1 parent 225535d commit 3e8336e
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 31 deletions.
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ android {
}
}

repositories {

maven { url 'https://jitpack.io' }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
//compile project(':Tapleader-SDK')
compile project(':Tapleader-SDK')

compile 'com.github.tapleader:tapleader-sdk-android:v1.4.1'
//compile 'com.github.tapleader:tapleader-sdk-android:v1.4.1'
}
30 changes: 23 additions & 7 deletions Sample/src/main/java/com/tapleader/test/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,36 @@ public void onClick(View v) {
findViewById(R.id.btn_event).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Double value=null;
int count=0;
try {
String name = ((EditText) findViewById(R.id.eventName)).getText().toString();
Double value = Double.valueOf(((EditText) findViewById(R.id.eventValue)).getText().toString());
int count = Integer.valueOf(((EditText) findViewById(R.id.eventValue)).getText().toString());

try {
value = Double.valueOf(((EditText) findViewById(R.id.eventValue)).getText().toString());
}catch (Exception e){
Toast.makeText(MainActivity.this,"مقدار value باید عددی باشد",Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
try {
if(!((EditText) findViewById(R.id.eventValue)).getText().toString().isEmpty())
count = Integer.valueOf(((EditText) findViewById(R.id.count)).getText().toString());
}catch (Exception e){
Toast.makeText(MainActivity.this,"مقدار count باید عددی باشد",Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
HashMap<String, Double> d = new HashMap<>();
for (int i = 0; i < count; i++) {
d.put("My details key " + i, new Random().nextDouble());
}
com.tapleader.Tapleader.event(name, value, d);
if(name!=null && value!=null)
com.tapleader.Tapleader.event(name, value, d);
else
Toast.makeText(MainActivity.this,"فیلد name و value اجباریست!",Toast.LENGTH_SHORT).show();

Toast.makeText(getBaseContext(), "Event saved!", Toast.LENGTH_SHORT).show();
((EditText) findViewById(R.id.eventName)).setText("");
((EditText) findViewById(R.id.eventValue)).setText("");
((EditText) findViewById(R.id.count)).setText("");
((EditText) findViewById(R.id.eventName)).setText("Sample Name");
((EditText) findViewById(R.id.eventValue)).setText("1.4");
((EditText) findViewById(R.id.count)).setText("0");
}catch (Exception e){
e.printStackTrace();
}
Expand Down
12 changes: 8 additions & 4 deletions Sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,35 @@
android:layout_below="@+id/button"
android:gravity="center"
android:orientation="vertical">

<EditText
android:id="@+id/eventName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EVENT NAME"/>
android:hint="EVENT NAME"
android:text="Sample name" />

<EditText
android:id="@+id/eventValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EVENT Value"
android:inputType="number"
android:hint="EVENT Value"/>
android:text="1.4" />

<EditText
android:id="@+id/count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Count of Random Details"
android:inputType="number" />
android:inputType="number"
android:text="0" />

<Button
android:id="@+id/btn_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send event"/>

</LinearLayout>
</RelativeLayout>
4 changes: 2 additions & 2 deletions Tapleader-SDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 15
versionName "1.4.1"
versionCode 16
versionName "1.4.2"

}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;

import org.json.JSONException;
Expand Down Expand Up @@ -234,8 +235,8 @@ public void setAlarm(Context context) {
intent.setAction(Constants.Action.ACTION_ALARM_MANAGER);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis()+INTERVAL,INTERVAL, alarmIntent);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime()+INTERVAL,INTERVAL, alarmIntent);
ComponentName receiver = new ComponentName(context, TBroadcastManager.class);
PackageManager pm = context.getPackageManager();

Expand Down
32 changes: 22 additions & 10 deletions Tapleader-SDK/src/main/java/com/tapleader/TModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
Expand Down Expand Up @@ -658,9 +659,19 @@ static TEventObject getModel(String name, double value, String detailsJsonArray)
JSONArray details=new JSONArray(detailsJsonArray);
HashMap<String,Double> map=new HashMap<>();
for(int i=0;i<details.length();i++){
String nameKey=details.getJSONObject(i).keys().next();
String valueKey=details.getJSONObject(i).keys().next();
map.put(nameKey,details.getJSONObject(i).getDouble(valueKey));
String nameKey=null;
String valueKey=null;
Iterator<String> keys= details.getJSONObject(i).keys();
try {
if(keys.hasNext())
nameKey = keys.next();
if(keys.hasNext())
valueKey = keys.next();
}catch (Exception e){
TLog.e("TEventObject#getModel#getKeys",e);
}
if(nameKey!=null)
map.put(nameKey,details.getJSONObject(i).getDouble(nameKey));
}
object.setDetails(map);
return object;
Expand All @@ -677,13 +688,15 @@ public JSONObject getJsonObject(){
object.put("EventName", getEventName());
object.put("Value", getValue());
JSONArray array = new JSONArray();
for (Map.Entry<String, Double> d : details.entrySet()) {
JSONObject detail = new JSONObject();
detail.put("Key", d.getKey());
detail.put("Value", d.getValue());
array.put(detail);
if(details!=null && details.size()>0) {
for (Map.Entry<String, Double> d : details.entrySet()) {
JSONObject detail = new JSONObject();
detail.put("Key", d.getKey());
detail.put("Value", d.getValue());
array.put(detail);
}
object.put("Details", array);
}
object.put("Details", array);
return object;
}catch (Exception e){
TLog.e("TEventObject#getJsonObject",e);
Expand All @@ -692,7 +705,6 @@ public JSONObject getJsonObject(){
}
@Override
public String toString() {

return super.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onServerResponse(JSONObject data) {

@Override
public void onServerError(String message, int code) {

TLog.d("TOfflineResponse#installResponse","on server error: "+message+" code"+code);
}
};

Expand All @@ -49,6 +49,8 @@ public void onServerResponse(JSONObject data) {
int status=data.getInt("Status");
if (status == Constants.Code.REQUEST_SUCCESS) {
OfflineStore.initialize(context).deleteRequest(id);
TUtils.updateLastPushActivityLogTime(context,System.currentTimeMillis());

} else {
//do nothing
}
Expand All @@ -59,7 +61,7 @@ public void onServerResponse(JSONObject data) {

@Override
public void onServerError(String message, int code) {

TLog.d("TOfflineResponse#activityTrackingResponse","on server error: "+message+" code"+code);
}
};

Expand Down
3 changes: 2 additions & 1 deletion Tapleader-SDK/src/main/java/com/tapleader/TService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onTrimMemory(int level) {
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
INTERVAL=2*AlarmManager.INTERVAL_HOUR;
INTERVAL=AlarmManager.INTERVAL_HOUR;
break;
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
Expand Down Expand Up @@ -98,6 +98,7 @@ public void onChange(boolean isConnected) {
isConnectedToNet.set(isConnected);
if(isConnected && mOfflineStore!=null){
binder.handleRequests(mOfflineStore.getAllRequests());
binder.commitEvents();
}
}

Expand Down

0 comments on commit 3e8336e

Please sign in to comment.