1

in the process of creating an application I ran into a couple of problems with the code, the bottom line is that the person opens the application presses the "get" button, watches the advertising video and receives the promotional code, but is faced with a problem if the person turns off the commercial or receives the promotional code it cannot already open the movie, the second problem is related to the implementation of the page update; I used SwipeRefresh Layout animation but there is nothing updated.

Application code:

public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {

    private static final String TAG = "MainActivity";

    AdView mAdView;

    Button mButtonGive, mButtonOrig, mButtonAmedia, mButtonIvi;
    TextView mTextPromo;

    RewardedVideoAd mAd;

    ClipboardManager clipboardManager;
    ClipData clipData;

    FirebaseFirestore mRef = FirebaseFirestore.getInstance();
    DocumentReference mPapaRef = mRef.collection("Promocode").document("Papa_Johns");

    SwipeRefreshLayout mSwipeRefresh;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mButtonGive = findViewById(R.id.mButtonGivePapa);
        mTextPromo = findViewById(R.id.mTextPromoPapa);
        mButtonOrig = findViewById(R.id.mButtonBuyOrig);
        mButtonAmedia = findViewById(R.id.mButtonBuyAmedia);
        mButtonIvi = findViewById(R.id.mButtonBuyIvi);

        mSwipeRefresh = findViewById(R.id.swipeRefresh);
        mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.i(TAG, "onRefresh called from SwipeRefreshLayout");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mSwipeRefresh.setRefreshing(false);
                    }
                }, 3000);
            }
        });
        mSwipeRefresh.setColorSchemeResources(R.color.colorLight, R.color.colorMiddle, R.color.colorPrimary);

        MobileAds.initialize(this, "ca-app-pub-7120970387686966~9640430308");
        mAd = MobileAds.getRewardedVideoAdInstance(this);
        mAd.setRewardedVideoAdListener(this);

        mAd.loadAd("ca-app-pub-7120970387686966/4195342567", new AdRequest.Builder().build());


        MobileAds.initialize(this, "ca-app-pub-7120970387686966/2942750897");

        mAdView = findViewById(R.id.mBanner);
        AdRequest adRequest1 = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest1);


        mButtonGive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTextPromo.setText("");
                mPapaRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                        if (task.isSuccessful()) {
                            DocumentSnapshot document = task.getResult();
                            assert document != null;
                            if (document.exists()) {
                                List<String> promocodes = (List<String>) document.get("Promo");
                                if (promocodes.size() > 0) {
                                    if (mAd.isLoaded()){
                                        mAd.show();
                                    }
                                } else {
                                    mTextPromo.setText("Купонов нет ;(");
                                }
                            } else {
                                Log.d(TAG, "No such document");
                            }

                        }
                        else {
                            Log.d(TAG, "get failed with ", task.getException());
                        }
                    }

                });

            }
        });

        clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        mTextPromo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = mTextPromo.getText().toString();
                clipData = ClipData.newPlainText("text", text);
                clipboardManager.setPrimaryClip(clipData);

                Toast.makeText(getApplicationContext(),"Скопировано в буфер обмена", Toast.LENGTH_SHORT).show();
            }
        });

        mButtonOrig.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Intent broIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://clc.to/origin_gift"));
                    startActivity(broIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        mButtonAmedia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Intent broIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://clc.to/amediateka_gift"));
                    startActivity(broIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        mButtonIvi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Intent broIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://clc.to/ivi_account"));
                    startActivity(broIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    }

    @Override
    public void onRewardedVideoAdLoaded() {
    }

    @Override
    public void onRewardedVideoAdOpened() {

    }

    @Override
    public void onRewardedVideoStarted() {

    }

    @Override
    public void onRewardedVideoAdClosed() {

    }

    @Override
    public void onRewarded(RewardItem rewardItem) {

    }

    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int i) {

    }

    @Override
    public void onRewardedVideoCompleted() {
        mPapaRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    DocumentSnapshot document = task.getResult();
                    assert document != null;
                    if (document.exists()) {
                        List<String> promocodes = (List<String>) document.get("Promo");
                        if (promocodes.size() > 0) {
                            int a = new Random().nextInt(promocodes.size());
                            mPapaRef.update("Promo", FieldValue.arrayRemove(promocodes.get(a)));
                            mTextPromo.setText(promocodes.get(a));
                        }
                    }
                }
            }
        });
    }
}

Logcat:

W/Ads: #004 The webview is destroyed. Ignoring action.

I/chatty: uid=10091(ru.redstart) identical 6 lines

W/Ads: #004 The webview is destroyed. Ignoring action.

W/Ads: Not enough space to show ad. Needs 412x90 dp, but only has 411x718 dp.

W/Ads: Not enough space to show ad. Needs 412x90 dp, but only has 53x718 dp.

W/Ads: Not enough space to show ad. Needs 412x90 dp, but only has 411x694 dp.

W/Ads: Not enough space to show ad. Needs 412x90 dp, but only has 53x694 dp.

D/EGL_emulation: eglMakeCurrent: 0xdcf64ea0: ver 2 0 (tinfo 0xc2221880)

I/Ads: This request is sent from a test device.

I/Ads: SDK version: afma-sdk-a-v15000000.15000000.0

I/Ads: Ad failed to load : 3

And my Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ru.redstart">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-7120970387686966~9640430308"/>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
Community
  • 1
  • 1

0 Answers0