Skip to content

Commit

Permalink
feat(unification): add setter for auto refresh interval in seconds #370
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinPostindustria committed Mar 22, 2022
1 parent 89c0045 commit 2fac52d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ object AdTypesRepository {
)
)

fun useOpenXServer() {
PrebidMobile.setPrebidServerAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d")
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid.openx.net/openrtb2/auction"))
}

private fun useTestServer() {
PrebidMobile.setPrebidServerAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d")
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid-server-test-j.prebid.org/openrtb2/auction"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager
import org.prebid.mobile.Host
import org.prebid.mobile.PrebidMobile
import org.prebid.mobile.prebidkotlindemo.databinding.ActivityDemoBinding

class DemoActivity : AppCompatActivity() {
Expand Down Expand Up @@ -57,7 +55,7 @@ class DemoActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_demo)

useOpenXServer()
AdTypesRepository.useOpenXServer()
useFakeGDPR()
parseArguments()
initViews()
Expand Down Expand Up @@ -100,9 +98,4 @@ class DemoActivity : AppCompatActivity() {
}
}

private fun useOpenXServer() {
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid.openx.net/openrtb2/auction"))
PrebidMobile.setPrebidServerAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@

import java.util.*;

public abstract class AdUnit {
import static org.prebid.mobile.PrebidMobile.AUTO_REFRESH_DELAY_MAX;
import static org.prebid.mobile.PrebidMobile.AUTO_REFRESH_DELAY_MIN;

private static final int MIN_AUTO_REFRESH_PERIOD_MILLIS = 30_000;
public abstract class AdUnit {

/**
* Auto refresh time period in millis. 0 for disabling auto refresh.
* Can't be less than MIN_AUTO_REFRESH_PERIOD_MILLIS.
*/
private int periodMillis = 0;
protected AdUnitConfiguration configuration = new AdUnitConfiguration();

@Nullable
Expand All @@ -56,12 +52,20 @@ public abstract class AdUnit {
configuration.setAdUnitIdentifierType(adType);
}

public void setAutoRefreshPeriodMillis(@IntRange(from = MIN_AUTO_REFRESH_PERIOD_MILLIS) int periodMillis) {
if (periodMillis < MIN_AUTO_REFRESH_PERIOD_MILLIS) {
LogUtil.w("Auto refresh time can't be less then: " + MIN_AUTO_REFRESH_PERIOD_MILLIS);
return;
}
this.periodMillis = periodMillis;
/**
* @deprecated Please use setAutoRefreshInterval() in seconds!
*/
@Deprecated
public void setAutoRefreshPeriodMillis(
@IntRange(from = AUTO_REFRESH_DELAY_MIN, to = AUTO_REFRESH_DELAY_MAX) int periodMillis
) {
configuration.setAutoRefreshDelay(periodMillis / 1000);
}

public void setAutoRefreshInterval(
@IntRange(from = AUTO_REFRESH_DELAY_MIN / 1000, to = AUTO_REFRESH_DELAY_MAX / 1000) int seconds
) {
configuration.setAutoRefreshDelay(seconds);
}

public void resumeAutoRefresh() {
Expand Down Expand Up @@ -141,10 +145,10 @@ public void fetchDemand(@NonNull Object adObj, @NonNull OnCompleteListener liste
createBidListener(listener)
);

if (periodMillis > 0) {
if (configuration.getAutoRefreshDelay() > 0) {
BidLoader.BidRefreshListener bidRefreshListener = () -> true;
bidLoader.setBidRefreshListener(bidRefreshListener);
LogUtil.v("Start fetching bids with auto refresh millis: " + periodMillis);
LogUtil.v("Start fetching bids with auto refresh millis: " + configuration.getAutoRefreshDelay());
} else {
bidLoader.setBidRefreshListener(null);
LogUtil.v("Start a single fetching.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ public class PrebidMobile {
/**
* Maximum refresh interval allowed. 120 seconds
*/
public static final int AUTO_REFRESH_DELAY_MAX = 120000;
public static final int AUTO_REFRESH_DELAY_MAX = 120_000;

/**
* Default refresh interval. 60 seconds
* Used when the refresh interval is not in the AUTO_REFRESH_DELAY_MIN & AUTO_REFRESH_DELAY_MAX range.
*/
public static final int AUTO_REFRESH_DELAY_DEFAULT = 60000;
public static final int AUTO_REFRESH_DELAY_DEFAULT = 60_000;

/**
* Minimum refresh interval allowed. 15 seconds
* Minimum refresh interval allowed. 30 seconds
*/
public static final int AUTO_REFRESH_DELAY_MIN = 15000;
public static final int AUTO_REFRESH_DELAY_MIN = 30_000;

/**
* Open measurement SDK version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ public boolean isBuiltInVideo() {
return isBuiltInVideo;
}

public void setAutoRefreshDelay(int autoRefreshDelay) {
if (autoRefreshDelay < 0) {
public void setAutoRefreshDelay(int autoRefreshDelayInSeconds) {
if (autoRefreshDelayInSeconds < 0) {
LogUtil.error(TAG, "Auto refresh delay can't be less then 0.");
return;
}
if (autoRefreshDelay == 0) {
if (autoRefreshDelayInSeconds == 0) {
LogUtil.debug(TAG, "Only one request, without auto refresh.");
autoRefreshDelayInMillis = 0;
return;
}
autoRefreshDelayInMillis = Utils.clampAutoRefresh(autoRefreshDelay);
autoRefreshDelayInMillis = Utils.clampAutoRefresh(autoRefreshDelayInSeconds);
}

public int getAutoRefreshDelay() {
Expand Down

0 comments on commit 2fac52d

Please sign in to comment.