Search in sources :

Example 1 with User

use of app.insti.api.model.User 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 2 with User

use of app.insti.api.model.User 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 3 with User

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

the class ComplaintDetailsFragment method addVotesToView.

public void addVotesToView(Venter.Complaint detailedComplaint) {
    upVotesList.clear();
    for (User users : detailedComplaint.getUsersUpVoted()) {
        upVotesList.add(users);
    }
    upVotesAdapter.setList(upVotesList);
    upVotesAdapter.notifyDataSetChanged();
    textViewVoteUpLabel.setText("Up Votes (" + detailedComplaint.getUsersUpVoted().size() + ")");
}
Also used : User(app.insti.api.model.User)

Example 4 with User

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

the class ExploreFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // Initialize
    sessionId = Utils.getSessionIDHeader();
    initRecyclerView();
    Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
    toolbar.setTitle("Explore");
    Utils.setSelectedMenuItem(getActivity(), R.id.nav_explore);
    final EditText searchEditText = getView().findViewById(R.id.explore_search);
    // Get all bodies
    if (allBodies.size() == 0) {
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.getAllBodies(sessionId).enqueue(new EmptyCallback<List<Body>>() {

            @Override
            public void onResponse(Call<List<Body>> call, Response<List<Body>> response) {
                allBodies = response.body();
                bodies = allBodies;
                updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
            }
        });
    } else {
        // Check if search box is not empty
        if (searchEditText.getText() != null && !searchEditText.getText().toString().equals("")) {
            updateAdapter(bodies, events, users);
        } else {
            updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
        }
        getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
    }
    // Close keyboard on search click
    searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                MainActivity.hideKeyboard(getActivity());
                return true;
            }
            return false;
        }
    });
    // Search on text change in search
    searchEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // Do nothing
        }

        @Override
        public void afterTextChanged(Editable s) {
            currentQuery = s.toString();
            if (currentQuery.length() >= 3) {
                doSearch(searchEditText.getText().toString());
            } else if (currentQuery.length() == 0) {
                updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
            }
        }
    });
}
Also used : EditText(android.widget.EditText) User(app.insti.api.model.User) ArrayList(java.util.ArrayList) KeyEvent(android.view.KeyEvent) KeyEvent(android.view.KeyEvent) Event(app.insti.api.model.Event) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 5 with User

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

the class BodyFragment method displayBody.

private void displayBody() {
    /* Skip if we're already destroyed */
    if (getActivity() == null || getView() == null)
        return;
    if (body != min_body)
        bodyDisplayed = true;
    bodyPicture = (ImageView) getActivity().findViewById(R.id.body_picture);
    /* Load only low res image if transition is not completed */
    if (transitionEnded) {
        Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
    } else {
        Picasso.get().load(Utils.resizeImageUrl(body.getBodyImageURL())).into(bodyPicture);
    }
    /* Skip for min body */
    if (body == min_body) {
        return;
    }
    bodyPicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomImageFromThumb(bodyPicture);
            final FloatingActionButton fab = getView().findViewById(R.id.edit_fab);
            fab.hide();
        }
    });
    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    final List<Role> roles = body.getBodyRoles();
    final List<User> users = new ArrayList<>();
    for (Role role : roles) {
        if (role.getRoleUsersDetail() != null) {
            for (User user : role.getRoleUsersDetail()) {
                user.setCurrentRole(role.getRoleName());
                users.add(user);
            }
        }
    }
    final List<CardInterface> cards = new ArrayList<>();
    cards.add(new BodyHeadCard(body));
    addWithTitleCard(cards, body.getBodyEvents(), "Events");
    addWithTitleCard(cards, users, "People");
    addWithTitleCard(cards, body.getBodyChildren(), "Organizations");
    addWithTitleCard(cards, body.getBodyParents(), "Part of");
    final RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.body_recycler_view);
    GenericAdapter genericAdapter = new GenericAdapter(cards, this);
    recyclerView.setAdapter(genericAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
    /* Show update button if role */
    if (((MainActivity) getActivity()).editBodyAccess(body)) {
        final FloatingActionButton fab = getView().findViewById(R.id.edit_fab);
        fab.show();
        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0)
                    fab.hide();
                else
                    fab.show();
            }
        });
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WebViewFragment webViewFragment = new WebViewFragment();
                Bundle bundle = new Bundle();
                bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_UPDATE_BODY);
                bundle.putString(Constants.WV_ID, body.getBodyID());
                webViewFragment.setArguments(bundle);
                ((MainActivity) getActivity()).updateFragment(webViewFragment);
            }
        });
    }
}
Also used : CardInterface(app.insti.interfaces.CardInterface) User(app.insti.api.model.User) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MainActivity(app.insti.activity.MainActivity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Point(android.graphics.Point) Role(app.insti.api.model.Role) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView) GenericAdapter(app.insti.adapter.GenericAdapter) BodyHeadCard(app.insti.utils.BodyHeadCard)

Aggregations

User (app.insti.api.model.User)8 Bundle (android.os.Bundle)4 RetrofitInterface (app.insti.api.RetrofitInterface)4 Toolbar (androidx.appcompat.widget.Toolbar)3 Event (app.insti.api.model.Event)2 Role (app.insti.api.model.Role)2 ArrayList (java.util.ArrayList)2 Point (android.graphics.Point)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (app.insti.activity.MainActivity)1 GenericAdapter (app.insti.adapter.GenericAdapter)1 Achievement (app.insti.api.model.Achievement)1