Search in sources :

Example 11 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class RecyclerViewFragment method updateData.

/**
 * Update the data clearing existing
 */
protected void updateData() {
    // Skip if we're already destroyed
    if (getActivity() == null || getView() == null)
        return;
    // Clear variables
    allLoaded = false;
    // Keep current search query
    final String requestSearchQuery = searchQuery;
    // Make the request
    String sessionIDHeader = Utils.getSessionIDHeader();
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    Call<List<T>> call = getCall(retrofitInterface, sessionIDHeader, 0);
    call.enqueue(new Callback<List<T>>() {

        @Override
        public void onResponse(Call<List<T>> call, Response<List<T>> response) {
            // Check if search query was changed in the meanwhile
            if (!Objects.equals(requestSearchQuery, searchQuery)) {
                return;
            }
            // Update display
            if (response.isSuccessful()) {
                List<T> posts = response.body();
                displayData(posts);
            }
            swipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onFailure(Call<List<T>> call, Throwable t) {
            swipeRefreshLayout.setRefreshing(false);
        }
    });
}
Also used : List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 12 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class SettingsFragment method toggleShowContact.

private void toggleShowContact(final SwitchPreferenceCompat showContactPref, Object option) {
    final boolean isChecked = (boolean) option;
    showContactPref.setEnabled(false);
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserShowContactPatchRequest(isChecked)).enqueue(new Callback<User>() {

        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            if (getActivity() == null || getView() == null)
                return;
            if (response.isSuccessful()) {
                showContactPref.setChecked(response.body().getShowContactNumber());
                showContactPref.setEnabled(true);
                Utils.currentUserCache = response.body();
            } else {
                showContactPref.setChecked(!isChecked);
                showContactPref.setEnabled(true);
            }
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            if (getActivity() == null || getView() == null)
                return;
            showContactPref.setChecked(!isChecked);
            showContactPref.setEnabled(true);
        }
    });
}
Also used : User(app.insti.api.model.User) UserShowContactPatchRequest(app.insti.api.request.UserShowContactPatchRequest) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 13 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class SettingsFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // Set toolbar title
    Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
    toolbar.setTitle("Settings");
    Utils.setSelectedMenuItem(getActivity(), R.id.nav_settings);
    if (Utils.currentUserCache == null) {
        // Get the user id
        Bundle bundle = getArguments();
        String userID = bundle.getString(Constants.USER_ID);
        // Fill in the user
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() {

            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                if (response.isSuccessful()) {
                    if (getActivity() == null || getView() == null)
                        return;
                    User user = response.body();
                    showContactPref.setChecked(user.getShowContactNumber());
                    showContactPref.setEnabled(true);
                    Utils.currentUserCache = user;
                }
            }
        });
    } else {
        showContactPref.setChecked(Utils.currentUserCache.getShowContactNumber());
        showContactPref.setEnabled(true);
    }
}
Also used : User(app.insti.api.model.User) Bundle(android.os.Bundle) Toolbar(androidx.appcompat.widget.Toolbar) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 14 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class SettingsFragment method logout.

private void logout() {
    final SessionManager sessionManager = new SessionManager(getContext());
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.logout(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<Void>() {

        @Override
        public void onResponse(Call<Void> call, Response<Void> response) {
            if (response.isSuccessful()) {
                sessionManager.logout();
                Utils.clearCookies(getActivity());
                Intent intent = new Intent(getContext(), LoginActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
        }
    });
}
Also used : LoginActivity(app.insti.activity.LoginActivity) SessionManager(app.insti.SessionManager) Intent(android.content.Intent) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 15 with RetrofitInterface

use of app.insti.api.RetrofitInterface in project IITB-App by wncc.

the class BodyHeadViewHolder method bindView.

public void bindView(final Body body, final Fragment fragment) {
    /* Set body information */
    bodyName.setText(body.getBodyName());
    bodySubtitle.setText(body.getBodyShortDescription());
    /* Return if it's a min body */
    if (body.getBodyDescription() == null) {
        return;
    }
    Utils.getMarkwon().setMarkdown(bodyDescription, body.getBodyDescription());
    /* Check if user is already following
         * Initialize follow button */
    setupFollowButton(fragment.getContext(), body);
    followButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
            retrofitInterface.updateBodyFollowing(Utils.getSessionIDHeader(), body.getBodyID(), body.getBodyUserFollows() ? 0 : 1).enqueue(new Callback<Void>() {

                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    if (response.isSuccessful()) {
                        body.setBodyUserFollows(!body.getBodyUserFollows());
                        body.setBodyFollowersCount(body.getBodyUserFollows() ? body.getBodyFollowersCount() + 1 : body.getBodyFollowersCount() - 1);
                        setupFollowButton(fragment.getContext(), body);
                    }
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                    Toast.makeText(fragment.getContext(), "Network Error", Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    /* Initialize web button */
    if (body.getBodyWebsiteURL() != null && !body.getBodyWebsiteURL().isEmpty()) {
        webBodyButton.setVisibility(View.VISIBLE);
        webBodyButton.setOnClickListener(new View.OnClickListener() {

            String bodywebURL = body.getBodyWebsiteURL();

            @Override
            public void onClick(View view) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bodywebURL));
                fragment.startActivity(browserIntent);
            }
        });
    }
    /* Initialize share button */
    shareBodyButton.setOnClickListener(new View.OnClickListener() {

        String shareUrl = ShareURLMaker.getBodyURL(body);

        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
            i.putExtra(Intent.EXTRA_TEXT, shareUrl);
            fragment.startActivity(Intent.createChooser(i, "Share URL"));
        }
    });
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

RetrofitInterface (app.insti.api.RetrofitInterface)35 List (java.util.List)12 Venter (app.insti.api.model.Venter)6 Call (retrofit2.Call)6 Response (retrofit2.Response)6 Event (app.insti.api.model.Event)5 ArrayList (java.util.ArrayList)5 Callback (retrofit2.Callback)5 User (app.insti.api.model.User)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Toolbar (androidx.appcompat.widget.Toolbar)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 SessionManager (app.insti.SessionManager)2 UpdatableList (app.insti.UpdatableList)2