com.octo.android.robospice.request.listener.RequestListener Java Examples

The following examples show how to use com.octo.android.robospice.request.listener.RequestListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppViewActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
private void executeSpiceRequestWithAppRate(long appId, float rating) {
    mRatingBar.setIsIndicator(true);
    spiceManager.execute(AptoideUtils.RepoUtils.buildRateRequest(appId, rating), new RequestListener<RateApp>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
            Toast.makeText(getActivity(), getString(R.string.error_occured), Toast.LENGTH_SHORT).show();
            mRatingBar.setIsIndicator(false);
        }

        @Override
        public void onRequestSuccess(RateApp rateApp) {
            mRatingBar.setIsIndicator(false);
            Toast.makeText(getActivity(), getString(R.string.appview_rate_Success), Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #2
Source File: AppViewActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void voteComment(int commentId, AddApkCommentVoteRequest.CommentVote vote) {
    RequestListener<GenericResponseV2> commentRequestListener = new AlmostGenericResponseV2RequestListener() {
        @Override
        public void CaseOK() {
            Toast.makeText(getActivity(), getString(R.string.vote_submitted), Toast.LENGTH_LONG).show();
        }
    };

    AptoideUtils.VoteUtils.voteComment(
            spiceManager,
            commentId,
            storeName,
            SecurePreferences.getInstance().getString("token", "empty"),
            commentRequestListener,
            vote);
}
 
Example #3
Source File: StoresActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void voteComment(int commentId, AddApkCommentVoteRequest.CommentVote vote) {

    RequestListener<GenericResponseV2> commentRequestListener = new AlmostGenericResponseV2RequestListener() {
        @Override
        public void CaseOK() {
            Toast.makeText(StoresActivity.this, getString(R.string.vote_submitted), Toast.LENGTH_LONG).show();
        }
    };

    AptoideUtils.VoteUtils.voteComment(
            spiceManager,
            commentId,
            storeName,
            SecurePreferences.getInstance().getString("token", "empty"),
            commentRequestListener,
            vote);
}
 
Example #4
Source File: MoreCommentsActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void voteComment(int commentId, AddApkCommentVoteRequest.CommentVote vote) {
    RequestListener<GenericResponseV2> commentRequestListener = new AlmostGenericResponseV2RequestListener() {
        @Override
        public void CaseOK() {
            Toast.makeText(MoreCommentsActivity.this, getString(R.string.vote_submitted), Toast.LENGTH_LONG).show();
        }
    };

    AptoideUtils.VoteUtils.voteComment(
            spiceManager,
            commentId,
            Defaults.DEFAULT_STORE_NAME,
            SecurePreferences.getInstance().getString("token", "empty"),
            commentRequestListener,
            vote);
}
 
Example #5
Source File: MainActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void voteComment(int commentId, AddApkCommentVoteRequest.CommentVote vote) {
    RequestListener<GenericResponseV2> commentRequestListener = new AlmostGenericResponseV2RequestListener() {
        @Override
        public void CaseOK() {
            Toast.makeText(MainActivity.this, getString(R.string.vote_submitted), Toast.LENGTH_LONG).show();
        }
    };

    AptoideUtils.VoteUtils.voteComment(
            spiceManager,
            commentId,
            Defaults.DEFAULT_STORE_NAME,
            SecurePreferences.getInstance().getString("token", "empty"),
            commentRequestListener,
            vote);
}
 
Example #6
Source File: AptoideUtils.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
public static void voteComment(SpiceManager spiceManager, int commentId,
                               String repoName,
                               String token,
                               RequestListener<GenericResponseV2> commentRequestListener,
                               AddApkCommentVoteRequest.CommentVote vote) {


    AddApkCommentVoteRequest commentVoteRequest = new AddApkCommentVoteRequest();

    commentVoteRequest.setRepo(repoName);
    commentVoteRequest.setToken(token);
    commentVoteRequest.setCmtid(commentId);
    commentVoteRequest.setVote(vote);

    spiceManager.execute(commentVoteRequest, commentRequestListener);
    Toast.makeText(Aptoide.getContext(), Aptoide.getContext().getString(R.string.casting_vote), Toast.LENGTH_SHORT).show();
}
 
Example #7
Source File: DownloadSpiceRequest.java    From Local-GSM-Backend with Apache License 2.0 5 votes vote down vote up
public static void executeWith(Context context, SpiceManager spiceManager) {
    spiceManager.execute(new DownloadSpiceRequest(context.getApplicationContext()), DownloadSpiceRequest.CACHE_KEY, DurationInMillis.ALWAYS_EXPIRED, new RequestListener<Result>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
            // ignore
        }

        @Override
        public void onRequestSuccess(DownloadSpiceRequest.Result result) {
            // ignore
        }
    });
}
 
Example #8
Source File: AppViewActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addApkFlagClick(String flag) {

    final DialogFragment dialogFragment = AptoideDialog.pleaseWaitDialog();
    dialogFragment.show(getChildFragmentManager(), "pleaseWaitDialog");

    AddApkFlagRequest flagRequest = new AddApkFlagRequest();
    flagRequest.setRepo(storeName);
    flagRequest.setMd5sum(md5sum);
    flagRequest.setFlag(flag);
    userVote = flag;
    spiceManager.execute(AptoideUtils.RepoUtils.buildFlagAppRequest(storeName, flag, md5sum), new RequestListener<GenericResponseV2>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
            dialogFragment.dismiss();
        }

        @Override
        public void onRequestSuccess(GenericResponseV2 genericResponseV2) {
            if (genericResponseV2.getStatus().toUpperCase().equals("OK")) {
                BusProvider.getInstance().post(new OttoEvents.AppViewRefresh());
                Toast.makeText(getActivity(), R.string.flag_added, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getActivity(), R.string.error_occured, Toast.LENGTH_SHORT).show();
            }
            spiceManager.removeDataFromCache(GetApp.class, md5sum);
            try {
                dialogFragment.dismiss();
            } catch (Exception e) {
                Logger.e(TAG, e.getMessage());
            }
        }
    });
}
 
Example #9
Source File: MoreHighlightedActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
        protected void executeSpiceRequest(boolean useCache) {

            final GetAdsRequest request = new GetAdsRequest();
            request.setLimit(ADS_LIMIT);
            request.setLocation("homepage");
            request.setKeyword("__NULL__");


            // in order to present the right info on screen after a screen rotation, always pass the bucketsize as cachekey
            spiceManager.execute(request, new RequestListener<ApkSuggestionJson>() {

                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    handleErrorCondition(spiceException);
                }

                @Override
                public void onRequestSuccess(ApkSuggestionJson apkSuggestionJson) {
                    handleSuccessCondition();
                    displayableList.clear();

                    if (apkSuggestionJson != null && apkSuggestionJson.ads != null && apkSuggestionJson.ads.size() > 0) {

                        for (ApkSuggestionJson.Ads ad : apkSuggestionJson.ads) {
                            AdItem adItem = getAdItem(ad);
                            displayableList.add(adItem);
                        }

//                        getAdapter().notifyDataSetChanged();
                    }

                    setRecyclerAdapter(getAdapter());
                }
            });

        }
 
Example #10
Source File: MoreVersionsActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
private void executeEndlessSpiceRequest() {
    long cacheExpiryDuration = useCache ? DurationInMillis.ONE_HOUR * 6 : DurationInMillis.ALWAYS_EXPIRED;
    spiceManager.execute(
            AptoideUtils.RepoUtils.GetMoreAppVersionsRequest(getArguments().getString(Constants.PACKAGENAME_KEY), limit, offset),
            getBaseContext() + "-packageName-" + getArguments().getString(Constants.PACKAGENAME_KEY) + "-" + BUCKET_SIZE + "-" + AptoideUtils.getSharedPreferences().getBoolean(Constants.MATURE_CHECK_BOX, false) + offset,
            cacheExpiryDuration, new RequestListener<DisplayableList>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    if (mLoading && !displayableList.isEmpty()) {
                        displayableList.remove(displayableList.size() - 1);
                        adapter.notifyItemRemoved(displayableList.size());
                    }
                }

                @Override
                public void onRequestSuccess(DisplayableList displayables) {

                    if (mLoading && !displayableList.isEmpty()) {
                        displayableList.remove(displayableList.size() - 1);
                        adapter.notifyItemRemoved(displayableList.size());
                    }


                    int index = displayableList.size();
                    displayableList.addAll(displayables);
                    adapter.notifyItemRangeInserted(index, displayables.size());

                    offset += displayables.size();
                    mLoading = false;
                }
            });

}
 
Example #11
Source File: MoreFriendsInstallsActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void executeSpiceRequest(boolean useCache) {

    long cacheExpiryDuration = useCache ? DurationInMillis.ONE_HOUR * 6 : DurationInMillis.ALWAYS_EXPIRED;

    ListApksInstallsRequest request = new ListApksInstallsRequest();

    // in order to present the right info on screen after a screen rotation, always pass the bucketsize as cachekey
    spiceManager.execute(
            request,
            getBaseContext() + BUCKET_SIZE + AptoideUtils.getSharedPreferences().getBoolean(Constants.MATURE_CHECK_BOX, false),
            cacheExpiryDuration,
            new RequestListener<TimelineListAPKsJson>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            handleErrorCondition(spiceException);
        }

        @Override
        public void onRequestSuccess(TimelineListAPKsJson timelineListAPKsJson) {
            handleSuccessCondition();
            displayableList.clear();
            setRecyclerAdapter(getAdapter());

            if (timelineListAPKsJson != null && timelineListAPKsJson.usersapks != null && timelineListAPKsJson.usersapks.size() > 0) {

                for (TimelineListAPKsJson.UserApk userApk : timelineListAPKsJson.usersapks) {
                    TimelineRow timeline = getTimelineRow(userApk);
                    displayableList.add(timeline);
                }

                getAdapter().notifyDataSetChanged();
            }
        }
    });

}
 
Example #12
Source File: DownloadService.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void startScheduledDownload(@NonNull final ScheduledDownloadItem scheduledDownload) {
    final GetApkInfoRequestFromMd5 requestFromMd5 = new GetApkInfoRequestFromMd5(this);
    requestFromMd5.setRepoName(scheduledDownload.getRepo_name());
    requestFromMd5.setMd5Sum(scheduledDownload.getMd5());

    final SpiceManager spiceManager = new SpiceManager(AptoideSpiceHttpService.class);
    if (!spiceManager.isStarted()){
        spiceManager.start(getApplicationContext());
    }
    spiceManager.execute(requestFromMd5, new RequestListener<GetApkInfoJson>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) { }

        @Override
        public void onRequestSuccess(final GetApkInfoJson getApkInfoJson) {
            if (getApkInfoJson == null) {
                return;
            }
            final GetApkInfoJson.Apk apk = getApkInfoJson.apk;
            final Download download = new Download();
            download.setMd5(scheduledDownload.getMd5());
            download.setId(scheduledDownload.getMd5().hashCode());
            download.setName(scheduledDownload.getName());
            download.setVersion(apk.getVername());
            download.setIcon(apk.getIcon());
            download.setPackageName(apk.getPackageName());
            startDownloadFromJson(getApkInfoJson, apk.getId().longValue(), download);
        }
    });
}
 
Example #13
Source File: MainActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void setMatureSwitchSetting(boolean value) {
    if (isLoggedin) {
        ChangeUserSettingsRequest request = new ChangeUserSettingsRequest();
        request.changeMatureSwitchSetting(value);
        spiceManager.execute(request, new RequestListener<GenericResponseV2>() {
            @Override
            public void onRequestFailure(SpiceException spiceException) {
            }

            @Override
            public void onRequestSuccess(GenericResponseV2 genericResponseV2) {
            }
        });
    }
}
 
Example #14
Source File: RegisterAdRefererRequest.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public static RequestListener<DefaultResponse> newDefaultResponse() {
    return new RequestListener<DefaultResponse>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {

        }

        @Override
        public void onRequestSuccess(RegisterAdRefererRequest.DefaultResponse defaultResponse) {

        }
    };
}
 
Example #15
Source File: MoreSearchActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
private void executeEndlessSpiceRequest() {
    long cacheExpiryDuration = useCache ? DurationInMillis.ONE_HOUR * 6 : DurationInMillis.ALWAYS_EXPIRED;
    spiceManager.execute(AptoideUtils.RepoUtils.buildSearchRequest(query, SearchRequest.SEARCH_LIMIT, SearchRequest.OTHER_REPOS_SEARCH_LIMIT, offset, storeName), MoreSearchActivity.class.getSimpleName() + query + offset, cacheExpiryDuration, new RequestListener<SearchResults>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
            if (mLoading && !displayableList.isEmpty()) {
                displayableList.remove(displayableList.size() - 1);
                getAdapter().notifyItemRemoved(displayableList.size());
            }
        }

        @Override
        public void onRequestSuccess(SearchResults searchResults) {

            if (mLoading && !displayableList.isEmpty()) {
                displayableList.remove(displayableList.size() - 1);
                getAdapter().notifyItemRemoved(displayableList.size());
            }

            List<SearchApk> apkList = searchResults.apkList;
            if (!apkList.isEmpty()) {
                displayableList.addAll(apkList);
            }
            offset += apkList.size();
            getAdapter().notifyDataSetChanged();
            swipeContainer.setEnabled(false);
            mLoading = false;
        }
    });

}
 
Example #16
Source File: SearchFragment.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
private void executeEndlessSpiceRequest() {
    long cacheDuration = DurationInMillis.ONE_HOUR * 6;
    spiceManager.execute(AptoideUtils.RepoUtils.buildSearchRequest(query, SearchRequest.SEARCH_LIMIT, SearchRequest.OTHER_REPOS_SEARCH_LIMIT, offset, u_offset),
            SearchActivity.CONTEXT+query+u_offset,cacheDuration,new RequestListener<SearchResults>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {

        }

        @Override
        public void onRequestSuccess(SearchResults searchResults) {

            if (mLoading && !displayables.isEmpty()) {
                displayables.remove(displayables.size() - 1);
                adapter.notifyItemRemoved(displayables.size());
            }

            List<SearchApk> uApkList = searchResults.uApkList;
            if (!uApkList.isEmpty()) {
                displayables.addAll(uApkList);
            }
            u_offset += uApkList.size();
            adapter.notifyDataSetChanged();
            mLoading = false;
        }
    });
}
 
Example #17
Source File: LoginActivity.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void getUserInfo(final OAuth oAuth, final String userName, final Mode mode, final String accountType, final String passwordOrToken) {
    Log.d(TAG, "Loading user info.");
    request = CheckUserCredentialsRequest.buildDefaultRequest(this, oAuth.getAccess_token());
    request.setRegisterDevice(registerDevice != null && registerDevice.isChecked());
    setShowProgress(true);
    spiceManager.execute(request, new RequestListener<CheckUserCredentialsJson>() {
        @Override
        public void onRequestFailure(SpiceException e) {
            Log.d(TAG, "Loading user info failed. " + e.getMessage());
            Toast.makeText(getBaseContext(), R.string.error_occured, Toast.LENGTH_SHORT).show();
            setShowProgress(false);
        }

        @Override
        public void onRequestSuccess(CheckUserCredentialsJson checkUserCredentialsJson) {
            Log.d(TAG, "User info loaded. status: " + checkUserCredentialsJson.getStatus() + ", userName: " + checkUserCredentialsJson.getUsername());
            if ("OK".equals(checkUserCredentialsJson.getStatus())) {
                updatePreferences(checkUserCredentialsJson, userName, mode.name(), oAuth.getAccess_token());
                if (null != checkUserCredentialsJson.getQueue()) {
                    hasQueue = true;
                }

                Bundle data = new Bundle();
                data.putString(AccountManager.KEY_ACCOUNT_NAME, userName);
                data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
                data.putString(AccountManager.KEY_AUTHTOKEN, oAuth.getRefreshToken());
                data.putString(PARAM_USER_PASS, passwordOrToken);

                final Intent res = new Intent();
                res.putExtras(data);
                finishLogin(res);
            } else {
                final HashMap<String, Integer> errorsMapConversion = Errors.getErrorsMap();
                Integer stringId;
                String message;
                for (ErrorResponse error : checkUserCredentialsJson.getErrors()) {
                    stringId = errorsMapConversion.get(error.code);
                    if (stringId != null) {
                        message = getString(stringId);
                    } else {
                        message = error.msg;
                    }

                    Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT).show();
                }
            }

            setShowProgress(false);
        }
    });
}
 
Example #18
Source File: BillingBinder.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken) throws RemoteException {
    Log.d("AptoideBillingService", "[getPurchases]: " + packageName + " " + type);

    final Bundle result = new Bundle();

    if (apiVersion < 3 || !(type.equals(ITEM_TYPE_INAPP) || type.equals(ITEM_TYPE_SUBS))) {
        result.putInt(RESPONSE_CODE, RESULT_DEVELOPER_ERROR);
        return result;
    }

    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = accountManager.getAccountsByType(Aptoide.getConfiguration().getAccountType());

    if(accounts.length == 0) {

        Log.d("AptoideBillingService", "BillingUnavailable: user not logged in");
        result.putStringArrayList(INAPP_PURCHASE_ITEM_LIST, new ArrayList<String>());
        result.putStringArrayList(INAPP_PURCHASE_DATA_LIST, new ArrayList<String>());
        result.putStringArrayList(INAPP_DATA_SIGNATURE_LIST, new ArrayList<String>());
        result.putInt(RESPONSE_CODE, RESULT_OK);

        return result;
    }

    try {
        String token = accountManager.blockingGetAuthToken(accounts[0], "Full access", true);

        if(token != null) {
            final CountDownLatch latch = new CountDownLatch(1);
            IabPurchasesRequest request = new IabPurchasesRequest();
            request.setApiVersion(Integer.toString(apiVersion));
            request.setPackageName(packageName);
            request.setType(type);
            request.setToken(token);

            manager.execute(request, packageName + "-getPurchases-"+type, DurationInMillis.ONE_SECOND*5, new RequestListener<IabPurchasesJson>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    result.putInt(RESPONSE_CODE, RESULT_ERROR);
                    latch.countDown();
                }

                @Override
                public void onRequestSuccess(IabPurchasesJson response) {
                    if("OK".equals(response.getStatus())) {

                        ArrayList<String> purchaseItemList = (ArrayList<String>) response.getPublisher_response().getItemList();
                        ArrayList<String> purchaseSignatureList = (ArrayList<String>) response.getPublisher_response().getSignatureList();

                        ArrayList<String> purchaseDataList = new ArrayList<String>();
                        for(IabPurchasesJson.PublisherResponse.PurchaseDataObject purchase : response.getPublisher_response().getPurchaseDataList()) {
                            Log.d("AptoideBillingService", "Purchase: " + purchase.getJson());
                            purchaseDataList.add(purchase.getJson());
                        }

                        result.putStringArrayList(INAPP_PURCHASE_ITEM_LIST, purchaseItemList);
                        result.putStringArrayList(INAPP_PURCHASE_DATA_LIST, purchaseDataList);
                        result.putStringArrayList(INAPP_DATA_SIGNATURE_LIST, purchaseSignatureList);
                        if(response.getPublisher_response().getInapp_continuation_token() != null) {
                            result.putString(INAPP_CONTINUATION_TOKEN, response.getPublisher_response().getInapp_continuation_token());
                        }
                        result.putInt(RESPONSE_CODE, RESULT_OK);
                    } else {
                        result.putInt(RESPONSE_CODE, RESULT_DEVELOPER_ERROR);
                    }
                    latch.countDown();
                }
            });

            latch.await();

        }

    } catch (Exception e) {
        e.printStackTrace();
        result.putInt(RESPONSE_CODE, RESULT_ERROR);
    }
    return result;
}
 
Example #19
Source File: AuthActivity.java    From android-atleap with Apache License 2.0 4 votes vote down vote up
protected <T> void executeSpiceRequest(SpiceRequest<T> request, Object requestCacheKey, long cacheExpiryDuration, RequestListener<T> callback) {
    changeProgressBarVisibility(true);
    getSpiceManager().execute(request, requestCacheKey, cacheExpiryDuration, callback);
}
 
Example #20
Source File: SponsorAdapter.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
public SponsorAdapter(Context context, int rowLayoutResourceId, ArrayList<Sponsor> list, RequestListener<Object> listener) {
    super(context, rowLayoutResourceId, list);
    this.inflater = LayoutInflater.from(context);
    this.listener = listener;
    this.context = context;
}
 
Example #21
Source File: SignetsRequestTask.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
public SignetsRequestTask(Context context, UserCredentials userCredentials, RequestListener<Object> requestListener, DatabaseHelper databaseHelper) {
    taskContext = new WeakReference<>(context);
    credentials = userCredentials;
    listener = requestListener;
    dbHelper = databaseHelper;
}
 
Example #22
Source File: StoreBinder.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isBillingAvailable(String packageName) throws RemoteException {
    Log.d("AptoideStore", "[isBillingAvailable]");

    if(Build.VERSION.SDK_INT<Build.VERSION_CODES.FROYO){
        return false;
    }

    try {

            final CountDownLatch latch = new CountDownLatch(1);
            IabAvailableRequest request = new IabAvailableRequest();
            request.setApiVersion(Integer.toString(3));

            request.setPackageName(packageName);
            final boolean[] result = { false };
            manager.execute(request, packageName + "-iabavalaible", DurationInMillis.ONE_MINUTE,new RequestListener<IabAvailableJson>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    latch.countDown();
                }

                @Override
                public void onRequestSuccess(IabAvailableJson response) {
                    if("OK".equals(response.getStatus())) {
                        if("OK".equals(response.getResponse().getIabavailable())) {
                            Log.d("AptoideStore", "billing is available");
                            result[0] = true;
                        }
                    }
                    latch.countDown();
                }
            });
            latch.await();


            return result[0];



    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
Example #23
Source File: CommunityFragment.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void executeReviewsSpiceRequest() {

        GetReviews.GetReviewList reviewRequest = new GetReviews.GetReviewList();

        reviewRequest.setOrderBy("id");
        reviewRequest.homePage = isHomePage();
        reviewRequest.limit = AptoideUtils.UI.getEditorChoiceBucketSize() * 4;

        spiceManager.execute(reviewRequest, "review-community-store-"+BUCKET_SIZE, useCache ? DurationInMillis.ONE_HOUR : DurationInMillis.ALWAYS_EXPIRED, new RequestListener<ReviewListJson>() {
            @Override
            public void onRequestFailure(SpiceException spiceException) {
                handleErrorCondition(spiceException);
            }

            @Override
            public void onRequestSuccess(ReviewListJson reviewListJson) {
                if ("OK".equals(reviewListJson.status) && reviewListJson.reviews != null && reviewListJson.reviews.size() > 0) {

                    // range is the size of the list. Because the HeaderRow replaces the placeholder, it's not considered an insertion
                    // why is this important? because of notifyItemRangeInserted
                    int range = reviewListJson.reviews.size();
                    int index = 0, originalIndex = 0;

                    boolean reviewPlaceHolderFound = false;
                    for (Displayable display : displayableList) {
                        if (display instanceof ReviewPlaceHolderRow) {
                            reviewPlaceHolderFound = true;
                            originalIndex = index = displayableList.indexOf(display);
                            break;
                        }
                    }

                    // prevent multiple requests adding to the beginning of the list
                    if (!reviewPlaceHolderFound)
                        return;

                    HeaderRow header = new HeaderRow(getString(R.string.reviews), true, REVIEWS_TYPE, BUCKET_SIZE, isHomePage(), Constants.GLOBAL_STORE);
                    header.FULL_ROW = AptoideUtils.UI.getEditorChoiceBucketSize();
                    displayableList.set(index++, header);

                    for (Review review : reviewListJson.reviews) {

                        ReviewRowItem reviewRowItem = getReviewRow(review);
                        reviewRowItem.FULL_ROW = 1;
                        displayableList.add(index++, reviewRowItem);
                    }

                    getAdapter().notifyItemRangeInserted(originalIndex + 1, range);
                }
            }
        });
    }
 
Example #24
Source File: CommunityFragment.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void executeCommentsRequest() {
        long cacheExpiryDuration = useCache ? DurationInMillis.ONE_HOUR * 6 : DurationInMillis.ALWAYS_EXPIRED;

        AllCommentsRequest request = new AllCommentsRequest();
        request.storeName = getStoreName();
        request.filters = Aptoide.filters;
        request.lang = AptoideUtils.StringUtils.getMyCountryCode(getContext());
        request.limit = AptoideUtils.UI.getEditorChoiceBucketSize() * 4;

        spiceManager.execute(request, getBaseContext() + getStoreId()+BUCKET_SIZE, cacheExpiryDuration, new RequestListener<GetComments>() {
                    @Override
                    public void onRequestFailure(SpiceException spiceException) {
                        Logger.printException(spiceException);
                    }

                    @Override
                    public void onRequestSuccess(GetComments get) {
                        if ("OK".equals(get.status) && get.list != null && get.list.size() > 0) {


                            // range is the size of the list. Because the HeaderRow replaces the placeholder, it's not considered an insertion
                            // why is this important? because of notifyItemRangeInserted
                            int range = get.list.size();
                            int index = 0, originalIndex = 0;

                            boolean placeHolderFound = false;
                            for (Displayable display : displayableList) {
                                if (display instanceof CommentPlaceHolderRow) {
                                    placeHolderFound = true;
                                    originalIndex = index = displayableList.indexOf(display);
                                    break;
                                }
                            }

                            // prevent multiple requests adding to beginning of the list
                            if (!placeHolderFound) {
                                return;
                            }

                            HeaderRow header = new HeaderRow(getString(R.string.comments), true, COMMENTS_TYPE, BUCKET_SIZE, isHomePage(), getStoreId());
                            header.FULL_ROW = AptoideUtils.UI.getEditorChoiceBucketSize();
                            displayableList.set(index++, header);

                            for (int i = 0; i < get.list.size(); i++) {
//                            for (int i = 0; i < 7; i++) {
                                Comment comment = get.list.get(i);

                                CommentItem commentItem = getCommentRow(comment);
                                displayableList.add(index++, commentItem);
                            }

                            getAdapter().notifyItemRangeInserted(originalIndex + 1, range);
                        }
                    }
                }
        );
    }
 
Example #25
Source File: IABPurchaseActivity.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private Bundle getPurchases(int apiVersion, String packageName, String type) throws RemoteException {
    Log.d("AptoideBillingService", "[getPurchases]: " + packageName + " " + type);

    final Bundle result = new Bundle();

    if (apiVersion < 3 || !(ITEM_TYPE_INAPP.equals(type) || ITEM_TYPE_SUBS.equals(type))) {
        result.putInt(RESPONSE_CODE, RESULT_DEVELOPER_ERROR);
        return result;
    }

    AccountManager accountManager = AccountManager.get(this);
    Account[] accounts = accountManager.getAccountsByType(Aptoide.getConfiguration().getAccountType());

    if(accounts.length == 0) {

        Log.d("AptoideBillingService", "BillingUnavailable: user not logged in");
        result.putStringArrayList(INAPP_PURCHASE_ITEM_LIST, new ArrayList<String>());
        result.putStringArrayList(INAPP_PURCHASE_DATA_LIST, new ArrayList<String>());
        result.putStringArrayList(INAPP_DATA_SIGNATURE_LIST, new ArrayList<String>());
        result.putInt(RESPONSE_CODE, RESULT_OK);

        return result;
    }

    try {
        String token = accountManager.blockingGetAuthToken(accounts[0], "Full access", true);

        if(token != null) {
            final CountDownLatch latch = new CountDownLatch(1);
            IabPurchasesRequest request = new IabPurchasesRequest();
            request.setApiVersion(Integer.toString(apiVersion));
            request.setPackageName(packageName);
            request.setType(type);
            request.setToken(token);

            spiceManager.execute(request, packageName + "-getPurchases-"+type, DurationInMillis.ONE_SECOND*5, new RequestListener<IabPurchasesJson>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    result.putInt(RESPONSE_CODE, RESULT_ERROR);
                    latch.countDown();
                }

                @Override
                public void onRequestSuccess(IabPurchasesJson response) {
                    if("OK".equals(response.getStatus())) {

                        ArrayList<String> purchaseItemList = (ArrayList<String>) response.getPublisher_response().getItemList();
                        ArrayList<String> purchaseSignatureList = (ArrayList<String>) response.getPublisher_response().getSignatureList();

                        ArrayList<String> purchaseDataList = new ArrayList<String>();
                        for(IabPurchasesJson.PublisherResponse.PurchaseDataObject purchase : response.getPublisher_response().getPurchaseDataList()) {
                            Log.d("AptoideBillingService", "Purchase: " + purchase.getJson());
                            purchaseDataList.add(purchase.getJson());
                        }

                        result.putStringArrayList(INAPP_PURCHASE_ITEM_LIST, purchaseItemList);
                        result.putStringArrayList(INAPP_PURCHASE_DATA_LIST, purchaseDataList);
                        result.putStringArrayList(INAPP_DATA_SIGNATURE_LIST, purchaseSignatureList);
                        if(response.getPublisher_response().getInapp_continuation_token() != null) {
                            result.putString(INAPP_CONTINUATION_TOKEN, response.getPublisher_response().getInapp_continuation_token());
                        }
                        result.putInt(RESPONSE_CODE, RESULT_OK);
                    } else {
                        result.putInt(RESPONSE_CODE, RESULT_DEVELOPER_ERROR);
                    }
                    latch.countDown();
                }
            });

            latch.await();

        }

    } catch (Exception e) {
        e.printStackTrace();
        result.putInt(RESPONSE_CODE, RESULT_ERROR);
    }
    return result;
}
 
Example #26
Source File: LoginActivity.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
public void submit(final Mode mode, final String userName, final String passwordOrToken, final String nameForGoogle) {
    Log.d(TAG, "Submitting. mode: " + mode.name() +", userName: " + userName + ", nameForGoogle: " + nameForGoogle);
    final String accountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);

    OAuth2AuthenticationRequest oAuth2AuthenticationRequest = new OAuth2AuthenticationRequest();
    oAuth2AuthenticationRequest.setPassword(passwordOrToken);
    oAuth2AuthenticationRequest.setUsername(userName);
    oAuth2AuthenticationRequest.setMode(mode);
    oAuth2AuthenticationRequest.setNameForGoogle(nameForGoogle);

    setShowProgress(true);
    spiceManager.execute(oAuth2AuthenticationRequest, new RequestListener<OAuth>() {
        @Override
        public void onRequestFailure(SpiceException spiceException) {
            Log.d(TAG, "OAuth filed: " + spiceException.getMessage());
            final Throwable cause = spiceException.getCause();
            if (cause != null) {
                final String error;
                if (cause instanceof RetrofitError) {
                    final RetrofitError retrofitError = (RetrofitError) cause;
                    final retrofit.client.Response response = retrofitError.getResponse();
                    if (response != null && (response.getStatus() == 400 || response.getStatus() == 401)) {
                        error = getString(R.string.error_AUTH_1);
                    } else {
                        error = getString(R.string.error_occured);
                    }
                } else {
                    error = getString(R.string.error_occured);
                }
                Toast.makeText(getBaseContext(), error, Toast.LENGTH_SHORT).show();
            }
            setShowProgress(false);
        }

        @Override
        public void onRequestSuccess(final OAuth oAuth) {
            if (oAuth.getStatus() != null && oAuth.getStatus().equals("FAIL")) {
                Log.d(TAG, "OAuth filed: " + oAuth.getError_description());
                AptoideUtils.UI.toastError(oAuth.getError());
                setShowProgress(false);
            } else {
                getUserInfo(oAuth, userName, mode, accountType, passwordOrToken);
                Analytics.Login.login(userName, mode);
            }
        }
    });
}
 
Example #27
Source File: FragmentSocialTimeline.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void init() {
            adapter = new EndlessWrapperAdapter(new TimelineAdapter(this, getActivity(), apks), this, getActivity());
            adapter.setRunInBackground(false);
            username = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("username", "");

            mSwipeRefreshLayout.setRefreshing(true);
            inviteFriends = LayoutInflater.from(getActivity()).inflate(R.layout.separator_invite_friends, null);
            getListView().addHeaderView(inviteFriends);

            final View invite = inviteFriends.findViewById(R.id.timeline_invite);
            final Context c = getActivity();
            ListUserFriendsRequest request = new ListUserFriendsRequest();

            request.setOffset(0);
            request.setLimit(150);

            manager.execute(request, "friendslist" + SecurePreferences.getInstance().getString("access_token", ""), DurationInMillis.ONE_HOUR / 2, new RequestListener<ListUserFriendsJson>() {

                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    Logger.e(TAG, spiceException.getMessage());
                }

                @Override
                public void onRequestSuccess(ListUserFriendsJson listUserFriendsJson) {
                    View.OnClickListener onClickListener;

                    if (listUserFriendsJson.getInactiveFriends().isEmpty()) {

                        onClickListener = new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
//                                FlurryAgent.logEvent("Social_Timeline_Clicked_On_Invite_Friends");
                                startActivity(new Intent(c, TimeLineNoFriendsInviteActivity.class));
                            }
                        };

                    } else {

                        onClickListener = new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
//                                FlurryAgent.logEvent("Social_Timeline_Clicked_On_Invite_Friends");
                                startActivity(new Intent(c, TimeLineFriendsInviteActivity.class));
                            }
                        };
                    }

                    invite.setOnClickListener(onClickListener);

                }
            });

            getListView().setItemsCanFocus(true);
            setListAdapter(adapter);
            setListShown(false);
            //force loading
            adapter.getView(0, null, null);

        }
 
Example #28
Source File: BaseWebserviceFragment.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void executeTimelineRequest() {

        if (AptoideUtils.AccountUtils.isLoggedIn(getActivity()) && AptoideUtils.getSharedPreferences().getBoolean(Preferences.TIMELINE_ACEPTED_BOOL, false)) {

            ListApksInstallsRequest listRelatedApkRequest = new ListApksInstallsRequest();
            listRelatedApkRequest.setLimit(String.valueOf(BUCKET_SIZE));

            // in order to present the right info on screen after a screen rotation, always pass the bucketsize as cachekey
            spiceManager.execute(listRelatedApkRequest, "MoreFriendsInstalls--" + BUCKET_SIZE, useCache ? DurationInMillis.ONE_HOUR : DurationInMillis.ALWAYS_EXPIRED, new RequestListener<TimelineListAPKsJson>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    Logger.printException(spiceException);
                }

                @Override
                public void onRequestSuccess(TimelineListAPKsJson timelineListAPKsJson) {
                    if (timelineListAPKsJson != null && timelineListAPKsJson.usersapks != null && timelineListAPKsJson.usersapks.size() > 0) {

                        // range is the size of the list. Because the HeaderRow replaces the placeholder, it's not considered an insertion
                        // why is this important? because of notifyItemRangeInserted
                        int range = timelineListAPKsJson.usersapks.size();
                        int index = 0, originalIndex = 0;

                        boolean placeHolderFound = false;
                        for (Displayable display : displayableList) {
                            if (display instanceof TimeLinePlaceHolderRow) {
                                placeHolderFound = true;
                                originalIndex = index = displayableList.indexOf(display);
                                break;
                            }
                        }

                        // prevent multiple requests adding to beginning of the list
                        if (!placeHolderFound) {
                            return;
                        }


                        HeaderRow header = new HeaderRow(getString(R.string.friends_installs), true, TIMELINE_TYPE, BUCKET_SIZE, isHomePage(), getStoreId());
                        displayableList.set(index++, header);

                        for (int i = 0; i < timelineListAPKsJson.usersapks.size(); i++) {
                            TimelineListAPKsJson.UserApk userApk = timelineListAPKsJson.usersapks.get(i);

                            TimelineRow timeline = getTimelineRow(userApk);

                            displayableList.add(index++, timeline);
                        }

                        adapter.notifyItemRangeInserted(originalIndex + 1, range);
                    }
                }


            });
        }
    }
 
Example #29
Source File: MoreListViewItemsActivity.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
protected void executeEndlessSpiceRequest() {
    long cacheExpiryDuration = useCache ? DurationInMillis.ONE_HOUR * 6 : DurationInMillis.ALWAYS_EXPIRED;

    spiceManager.execute(
            AptoideUtils.RepoUtils.buildViewItemsRequest(storeName, eventActionUrl, getLayoutMode(), offset),
            getBaseContext() + parseActionUrlIntoCacheKey(eventActionUrl) + getStoreId() + BUCKET_SIZE + AptoideUtils.getSharedPreferences().getBoolean(Constants.MATURE_CHECK_BOX, false) + offset,
            cacheExpiryDuration,
            new RequestListener<StoreHomeTab>() {
                @Override
                public void onRequestFailure(SpiceException spiceException) {
                    handleErrorCondition(spiceException);
                }

                @Override
                public void onRequestSuccess(StoreHomeTab tab) {
                    if (getView() == null) {
                        return;
                    }

                    if (mLoading && !displayableList.isEmpty()) {
                        displayableList.remove(displayableList.size() - 1);
                        adapter.notifyItemRemoved(displayableList.size());
                    }

                    int index = displayableList.size();
                    displayableList.addAll(tab.list);
                    adapter.notifyItemRangeInserted(index, tab.list.size());


                    // total and new offset is red here
                    offset = tab.offset;
                    total = tab.total;

                    mLoading = false;

                    // check for hidden items
                    if (tab.hidden > 0 && AptoideUtils.getSharedPreferences().getBoolean(Constants.SHOW_ADULT_HIDDEN, true) && getFragmentManager().findFragmentByTag(Constants.HIDDEN_ADULT_DIALOG) == null) {
                        AdultHiddenDialog dialog = new AdultHiddenDialog();
                        AptoideDialog.showDialogAllowingStateLoss(dialog, getFragmentManager(), Constants.HIDDEN_ADULT_DIALOG);
                    }
                }
            }
    );
}
 
Example #30
Source File: BaseWebserviceFragment.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
private void executeAdsSpiceRequest() {

        if (sponsoredCache == null) {
            if (args != null && args.getString("sponsoredCache") != null) {
                sponsoredCache = args.getString("sponsoredCache");
            } else {
                sponsoredCache = UUID.randomUUID().toString();
            }
        }

        final GetAdsRequest request = new GetAdsRequest();
        request.setLimit(BUCKET_SIZE);
        request.setLocation("homepage");
        request.setKeyword("__NULL__");


        // in order to present the right info on screen after a screen rotation, always pass the bucketsize as cachekey
        spiceManager.execute(request, sponsoredCache + "--" + BUCKET_SIZE, useCache ? DurationInMillis.ONE_HOUR : DurationInMillis.ALWAYS_EXPIRED, new RequestListener<ApkSuggestionJson>() {
            @Override
            public void onRequestFailure(SpiceException spiceException) {
            }

            @Override
            public void onRequestSuccess(ApkSuggestionJson apkSuggestionJson) {
                if (apkSuggestionJson != null && apkSuggestionJson.ads != null && apkSuggestionJson.ads.size() > 0) {

                    // range is the size of the list. Because the HeaderRow replaces the placeholder, it's not considered an insertion
                    // why is this important? because of notifyItemRangeInserted
                    int range = apkSuggestionJson.ads.size();
                    int index = 0, originalIndex = 0;

                    boolean adPlaceHolderFound = false;
                    for (Displayable display : displayableList) {
                        if (display instanceof AdPlaceHolderRow) {
                            adPlaceHolderFound = true;
                            originalIndex = index = displayableList.indexOf(display);
                            break;
                        }
                    }

                    // prevent multiple requests adding to beginning of the list
                    if (!adPlaceHolderFound)
                        return;


                    HeaderRow header = new HeaderRow(getString(R.string.highlighted_apps), true, ADS_TYPE, BUCKET_SIZE, isHomePage(), getStoreId());
                    displayableList.set(index++, header);

                    for (int i = 0; i < apkSuggestionJson.ads.size(); i++) {
                        ApkSuggestionJson.Ads ad = apkSuggestionJson.ads.get(i);

                        AdItem adItem = getAdItem(ad);

                        displayableList.add(index++, adItem);
                    }

                    adapter.notifyItemRangeInserted(originalIndex + 1, range);
                }
            }
        });
    }