Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from adobe/cleanup
Browse files Browse the repository at this point in the history
cleanup UI -> remove unused UI components
  • Loading branch information
yangyansong-adbe authored Oct 27, 2020
2 parents eff2a21 + ebf0b46 commit a3dcb72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@
*/
public class AnalyticsTab extends Fragment implements NavigationAware {

TextView lblQueueSize = null;
TextView lblTrackingIdentifier = null;
TextView lblVisitor = null;
TextView lblMinBatchSize = null;
Button btnEmitStateEvent = null;
Button btnEmitActionEvent = null;
Button btnClearQueuedHits = null;
Button btnSendQueuedHits = null;
RadioButton rdoOptIn = null;
RadioButton rdoOptOut = null;
RadioButton rdoOptUnknown = null;
Expand All @@ -67,9 +61,6 @@ public class AnalyticsTab extends Fragment implements NavigationAware {
Button btnSyncId = null;
Button btnGetSdkId = null;
Button btnAppendUrl = null;
String trackingIdentifier = "";
String visitorIdentifier = "";
String batchSize = "";

boolean userIsViewingThisFragment = true;
private static final String LOG_TAG = "Core Tab";
Expand Down Expand Up @@ -104,17 +95,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
//Create references to all our components
lblQueueSize = getView().findViewById(R.id.lblQueueSize);
lblMinBatchSize = getView().findViewById(R.id.lblMinBatchSize);
lblTrackingIdentifier = getView().findViewById(R.id.lblTrackingIdentifier);
lblVisitor = getView().findViewById(R.id.lblVisitor);

rdoOptIn = getView().findViewById(R.id.rdoOptIn);
rdoOptOut = getView().findViewById(R.id.rdoOptOut);
rdoOptUnknown = getView().findViewById(R.id.rdoOptUnknown);
btnEmitStateEvent = getView().findViewById(R.id.btn_emitStateEvent);
btnEmitActionEvent = getView().findViewById(R.id.btn_emitActionEvent);
btnClearQueuedHits = getView().findViewById(R.id.btn_clearQueuedHits);
btnSendQueuedHits = getView().findViewById(R.id.btn_sendQueuedHits);
btnGetPrivacy = getView().findViewById(R.id.btn_getPrivacy);
txtCurrentPrivacy = getView().findViewById(R.id.text_currentPrivacy);
btnCollectPII = getView().findViewById(R.id.btn_collectPII);
Expand All @@ -127,16 +113,6 @@ public void onViewCreated(View view, Bundle savedInstanceState){
btnGetSdkId = getView().findViewById(R.id.btn_getSdkId);
btnAppendUrl = getView().findViewById(R.id.btn_appendUrl);

//Setup button events
btnSendQueuedHits.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Analytics.sendQueuedHits();

showToast("Sent queued hits");
delayedRefresh(500);
}
});

btnCollectPII.setOnClickListener(new View.OnClickListener(){
@Override
Expand Down Expand Up @@ -260,16 +236,6 @@ public void run(){
}
});

btnClearQueuedHits.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Analytics.clearQueue();

showToast("Cleared queue");
delayedRefresh(500);
}
});

btnEmitActionEvent.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Expand All @@ -281,7 +247,6 @@ public void onClick(View v) {

showToast("Analytics action \""+eventName+"\" triggered");

delayedRefresh(500);
}
});

Expand All @@ -296,157 +261,40 @@ public void onClick(View v) {

showToast("Analytics state \""+eventName+"\" triggered");

delayedRefresh(500);
}
});

rdoOptIn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
MobileCore.setPrivacyStatus(MobilePrivacyStatus.OPT_IN);
delayedRefresh();
}
});
rdoOptOut.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
MobileCore.setPrivacyStatus(MobilePrivacyStatus.OPT_OUT);
delayedRefresh();
}
});
rdoOptUnknown.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
MobileCore.setPrivacyStatus(MobilePrivacyStatus.UNKNOWN);
delayedRefresh();
}
});



updateBatchLimit(10);


//Setup refresh timer
Timer timer = new Timer("Background polling timer for analytics status");
timer.scheduleAtFixedRate(new TimerTask(){
@Override
public void run() {
refresh();
}
}, 0, 10000);
}

public void updateBatchLimit(int limitNumber){
//Set batch limit
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("analytics.batchLimit", limitNumber);
MobileCore.updateConfiguration(data);
batchSize = Integer.toString(limitNumber);

refresh();
}

public void delayedRefresh(){
delayedRefresh(1000);
}
public void delayedRefresh(int delay){ //Used to refresh after a delay of 1 second - useful for showing immediate results after the user taps a button.
//Setup refresh timer
Timer timer = new Timer("Background polling timer for analytics status");
timer.schedule(new TimerTask(){
@Override
public void run() {
refresh();
}
}, delay);
}


private boolean isFirstRefresh = true;
public void refresh(){
if(!userIsViewingThisFragment){ //No need to refresh if the user isn't viewing the fragment. This will also prevent unneeded Adobe SDK events from being triggered.
return;
}
if(isFirstRefresh){ //Only refresh the identifiers automatically once. After this, refresh them only when changed (see event for btnSaveFreeTextEntry).
Analytics.getTrackingIdentifier(new AdobeCallback<String>() {
@Override
public void call(String s) {
trackingIdentifier = s;
if(s == null){
trackingIdentifier = "<none>";
}
refreshIdentifiers();
}
});
Analytics.getVisitorIdentifier(new AdobeCallback<String>() {
@Override
public void call(String s) {
visitorIdentifier = s;
if(s == null){
visitorIdentifier = "<none>";
}
refreshIdentifiers();
}
});
}
isFirstRefresh = false;

Analytics.getQueueSize(new AdobeCallback<Long>() {
@Override
public void call(final Long queueSize) {
getActivity().runOnUiThread(new Runnable(){
@Override
public void run(){
lblQueueSize.setText("Event queue length: "+queueSize);
}
});
}
});

getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
lblMinBatchSize.setText("Min Batch Size: " + batchSize);
}
});


//Refresh opting radio buttons
MobileCore.getPrivacyStatus(new AdobeCallback<MobilePrivacyStatus>() {
@Override
public void call(MobilePrivacyStatus mobilePrivacyStatus) {
if(mobilePrivacyStatus != null){
if(mobilePrivacyStatus.equals(MobilePrivacyStatus.OPT_IN)){
rdoOptIn.toggle();
}
else if(mobilePrivacyStatus.equals(MobilePrivacyStatus.OPT_OUT)){
rdoOptOut.toggle();
}
else{
rdoOptUnknown.toggle();
}
}
else{
rdoOptUnknown.toggle();
}
}
});
}

public void refreshIdentifiers(){
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
lblVisitor.setText("Visitor identifier: "+visitorIdentifier);
lblTrackingIdentifier.setText("Tracking identifier: "+trackingIdentifier);
}
});
}

@Override
public void OnNavigateTo() {
userIsViewingThisFragment = true;
delayedRefresh(500);
}

@Override
Expand Down
86 changes: 3 additions & 83 deletions Sample-App/app/src/main/res/layout/fragment_analytics_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,7 @@
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/lblStatusTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:text="Status" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<TextView
android:id="@+id/lblQueueSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Queue Size: 0" />

<TextView
android:id="@+id/lblMinBatchSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Min Batch Size: 0" />

<TextView
android:id="@+id/lblTrackingIdentifier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tracking identifier: " />

<TextView
android:id="@+id/lblVisitor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Visitor: " />

</LinearLayout>

</LinearLayout>
</androidx.cardview.widget.CardView>
android:layout_marginBottom="20dp"/>



Expand All @@ -94,42 +45,11 @@
android:id="@+id/lblEventingTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Manual Event Triggers" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">


<Button
android:id="@+id/btn_sendQueuedHits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/analytics_btnSendQueue" />

<Button
android:id="@+id/btn_clearQueuedHits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/analytics_btnClearQueue" />

</LinearLayout>

android:text="Trigger Analytics Events"
android:textStyle="bold" />

<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?android:attr/listDivider" />

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit a3dcb72

Please sign in to comment.