Search in sources :

Example 36 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class Qms method getChat.

public QmsChatModel getChat(final int userId, final int themeId) throws Exception {
    NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms&mid=" + userId + "&t=" + themeId).formHeader("xhr", "body");
    NetworkResponse response = Api.getWebClient().request(builder.build());
    return parseChat(response.getBody());
}
Also used : NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 37 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class Qms method findUser.

public List<ForumUser> findUser(final String nick) throws Exception {
    String encodedNick = URLEncoder.encode(nick, "UTF-8");
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=qms-xhr&action=autocomplete-username&q=" + encodedNick);
    List<ForumUser> list = new ArrayList<>();
    Matcher m = findUserPattern.matcher(response.getBody());
    while (m.find()) {
        ForumUser user = new ForumUser();
        user.setId(Integer.parseInt(m.group(1)));
        user.setNick(ApiUtils.fromHtml(m.group(2)));
        String avatar = m.group(3);
        if (avatar.substring(0, 2).equals("//")) {
            avatar = "https:".concat(avatar);
        } else if (avatar.substring(0, 1).equals("/")) {
            avatar = "https://4pda.ru".concat(avatar);
        }
        user.setAvatar(avatar);
        list.add(user);
    }
    return list;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ArrayList(java.util.ArrayList)

Example 38 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class Qms method sendNewTheme.

public QmsChatModel sendNewTheme(String nick, String title, String mess) throws Exception {
    NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms&action=create-thread&xhr=body&do=1").formHeader("username", nick).formHeader("title", title).formHeader("message", mess);
    NetworkResponse response = Api.getWebClient().request(builder.build());
    return parseChat(response.getBody());
}
Also used : NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 39 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class IntentHandler method redirectDownload.

private static void redirectDownload(String fileName, String url) {
    Toast.makeText(App.getContext(), String.format(App.get().getString(R.string.perform_request_link), fileName), Toast.LENGTH_SHORT).show();
    Observable.fromCallable(() -> Client.get().request(new NetworkRequest.Builder().url(url).withoutBody().build())).onErrorReturn(throwable -> new NetworkResponse(null)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
        if (response.getUrl() == null) {
            Toast.makeText(App.getContext(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
            return;
        }
        try {
            Activity activity = App.getActivity();
            if (!Preferences.Main.isSystemDownloader(null) || activity == null) {
                externalDownloader(response.getRedirect());
            } else {
                Runnable checkAction = () -> {
                    Toast.makeText(App.getContext(), String.format(App.get().getString(R.string.perform_request_link), fileName), Toast.LENGTH_SHORT).show();
                    try {
                        systemDownloader(fileName, response.getRedirect());
                    } catch (Exception exception) {
                        Toast.makeText(App.getContext(), R.string.perform_loading_error, Toast.LENGTH_SHORT).show();
                        externalDownloader(response.getRedirect());
                    }
                };
                App.get().checkStoragePermission(checkAction, activity);
            }
        } catch (Exception ex) {
            ACRA.getErrorReporter().handleException(ex);
        }
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) URLDecoder(java.net.URLDecoder) NewsMainFragment(forpdateam.ru.forpda.ui.fragments.news.main.NewsMainFragment) Environment(android.os.Environment) Uri(android.net.Uri) AnnounceFragment(forpdateam.ru.forpda.ui.fragments.other.AnnounceFragment) Intent(android.content.Intent) MentionsFragment(forpdateam.ru.forpda.ui.fragments.mentions.MentionsFragment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) ACRA(org.acra.ACRA) Matcher(java.util.regex.Matcher) ProfileFragment(forpdateam.ru.forpda.ui.fragments.profile.ProfileFragment) Toast(android.widget.Toast) TopicsFragment(forpdateam.ru.forpda.ui.fragments.topics.TopicsFragment) Client(forpdateam.ru.forpda.client.Client) BrandsFragment(forpdateam.ru.forpda.ui.fragments.devdb.BrandsFragment) QmsThemesFragment(forpdateam.ru.forpda.ui.fragments.qms.QmsThemesFragment) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) ForumRulesFragment(forpdateam.ru.forpda.ui.fragments.other.ForumRulesFragment) Log(android.util.Log) QmsChatFragment(forpdateam.ru.forpda.ui.fragments.qms.chat.QmsChatFragment) BrandFragment(forpdateam.ru.forpda.ui.fragments.devdb.BrandFragment) FLAG_ACTIVITY_NEW_TASK(android.content.Intent.FLAG_ACTIVITY_NEW_TASK) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) TabManager(forpdateam.ru.forpda.ui.TabManager) NewsDetailsFragment(forpdateam.ru.forpda.ui.fragments.news.details.NewsDetailsFragment) DeviceFragment(forpdateam.ru.forpda.ui.fragments.devdb.DeviceFragment) ThemeFragmentWeb(forpdateam.ru.forpda.ui.fragments.theme.ThemeFragmentWeb) ReputationFragment(forpdateam.ru.forpda.ui.fragments.reputation.ReputationFragment) DownloadManager(android.app.DownloadManager) FavoritesFragment(forpdateam.ru.forpda.ui.fragments.favorites.FavoritesFragment) AlertDialog(android.support.v7.app.AlertDialog) ImageViewerActivity(forpdateam.ru.forpda.ui.activities.imageviewer.ImageViewerActivity) ActivityNotFoundException(android.content.ActivityNotFoundException) App(forpdateam.ru.forpda.App) QmsContactsFragment(forpdateam.ru.forpda.ui.fragments.qms.QmsContactsFragment) SearchFragment(forpdateam.ru.forpda.ui.fragments.search.SearchFragment) Pattern(java.util.regex.Pattern) R(forpdateam.ru.forpda.R) Activity(android.app.Activity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ImageViewerActivity(forpdateam.ru.forpda.ui.activities.imageviewer.ImageViewerActivity) Activity(android.app.Activity) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 40 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class UpdateCheckerActivity method refreshInfo.

private void refreshInfo() {
    setRefreshing(true);
    updateContent.removeAllViews();
    Observable.fromCallable(() -> {
        NetworkResponse response = Client.get(getApplicationContext()).get(JSON_LINK);
        String body;
        body = response.getBody();
        return body;
    }).onErrorReturn(throwable -> "").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::checkSource);
}
Also used : Typeface(android.graphics.Typeface) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) ApiUtils(forpdateam.ru.forpda.api.ApiUtils) LocaleHelper(forpdateam.ru.forpda.common.LocaleHelper) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Client(forpdateam.ru.forpda.client.Client) View(android.view.View) Button(android.widget.Button) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ClientHelper(forpdateam.ru.forpda.client.ClientHelper) IntentHandler(forpdateam.ru.forpda.common.IntentHandler) BuildConfig(forpdateam.ru.forpda.BuildConfig) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) DynamicDialogMenu(forpdateam.ru.forpda.ui.views.DynamicDialogMenu) App(forpdateam.ru.forpda.App) Nullable(android.support.annotation.Nullable) R(forpdateam.ru.forpda.R) JSONArray(org.json.JSONArray) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)44 Matcher (java.util.regex.Matcher)27 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)25 ArrayList (java.util.ArrayList)8 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)6 Bundle (android.os.Bundle)3 RequestFile (forpdateam.ru.forpda.api.RequestFile)3 Context (android.content.Context)2 Uri (android.net.Uri)2 App (forpdateam.ru.forpda.App)2 R (forpdateam.ru.forpda.R)2 QmsMessage (forpdateam.ru.forpda.api.qms.models.QmsMessage)2 Client (forpdateam.ru.forpda.client.Client)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 Activity (android.app.Activity)1 DownloadManager (android.app.DownloadManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1