Skip to content

Commit

Permalink
Merge pull request #22 from rapidpro/hotfix/2.7.0
Browse files Browse the repository at this point in the history
Bug fixes and performance improvements
  • Loading branch information
johncordeiro authored Apr 19, 2017
2 parents 28e2ff8 + 2673b41 commit 17aedb3
Show file tree
Hide file tree
Showing 31 changed files with 496 additions and 277 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ android {
applicationId "in.ureport"
minSdkVersion 10
targetSdkVersion 23
versionCode 41
versionName "2.6.0"
versionCode 43
versionName "2.7.0"
multiDexEnabled true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
Expand All @@ -20,7 +19,6 @@
import in.ureport.managers.CountryProgramManager;
import in.ureport.managers.FirebaseManager;
import in.ureport.managers.UserManager;
import in.ureport.models.ChatRoom;
import in.ureport.models.User;
import in.ureport.models.holders.NavigationItem;
import in.ureport.views.adapters.NavigationAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void onClick(View view) {
}

UserGender gender = (UserGender) EditUserFragment.this.gender.getSelectedItem();
user.setGender(gender.getGender());
user.setGenderAsEnum(gender.getGender());

progressDialog = ProgressDialog.show(getActivity(), null, getString(R.string.load_message_wait), true, false);
Log.i(TAG, "onClick editUser ");
Expand Down
44 changes: 16 additions & 28 deletions app/src/main/java/in/ureport/fragments/RankingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Collections;
import java.util.List;
import com.marcorei.infinitefire.InfiniteFireArray;
import com.marcorei.infinitefire.InfiniteFireLinearRecyclerView;

import in.ureport.R;
import in.ureport.models.User;
import in.ureport.helpers.DividerItemDecoration;
import in.ureport.models.User;
import in.ureport.network.UserServices;
import in.ureport.views.adapters.RankingAdapter;

Expand All @@ -25,9 +24,7 @@ public class RankingFragment extends Fragment {

private static final String EXTRA_USER = "user";

private User user;

private RecyclerView rankingList;
private InfiniteFireLinearRecyclerView rankingList;

private UserServices userServices;

Expand All @@ -41,15 +38,6 @@ public static RankingFragment newInstance(User user) {
return rankingFragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getArguments();
if(extras != null && extras.containsKey(EXTRA_USER)) {
user = extras.getParcelable(EXTRA_USER);
}
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -65,24 +53,24 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
loadData();
}

private void loadData() {
userServices.loadRanking(new UserServices.OnLoadAllUsersListener() {
@Override
public void onLoadAllUsers(List<User> users) {
Collections.reverse(users);
RankingAdapter rankingAdapter = new RankingAdapter(users);
rankingList.setAdapter(rankingAdapter);
}
});
}

private void setupObjects() {
userServices = new UserServices();
}

private void setupView(View view) {
rankingList = (RecyclerView) view.findViewById(R.id.rankingList);
rankingList = (InfiniteFireLinearRecyclerView) view.findViewById(R.id.rankingList);
rankingList.setLayoutManager(new LinearLayoutManager(getActivity()));
rankingList.addItemDecoration(new DividerItemDecoration(getActivity()));
}

private void loadData() {
InfiniteFireArray<User> rankingArray = new InfiniteFireArray<>(User.class
, userServices.getRankingQuery(), 50, 50, false, false);

RankingAdapter rankingAdapter = new RankingAdapter(rankingArray);
rankingAdapter.setHasStableIds(true);

rankingList.setAdapter(rankingAdapter);
rankingList.setInfiniteFireArray(rankingArray);
}
}
104 changes: 21 additions & 83 deletions app/src/main/java/in/ureport/fragments/SelectModeratorsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,31 @@
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.marcorei.infinitefire.InfiniteFireArray;
import com.marcorei.infinitefire.InfiniteFireLinearRecyclerView;

import java.util.List;

import in.ureport.R;
import in.ureport.listener.ItemSelectionListener;
import in.ureport.managers.SearchManager;
import in.ureport.models.User;
import in.ureport.network.UserServices;
import in.ureport.views.adapters.UreportersAdapter;
import in.ureport.views.adapters.UreportersInfiniteAdapter;

/**
* Created by johncordeiro on 17/09/15.
*/
public class SelectModeratorsFragment extends Fragment implements SearchView.OnCloseListener
, SearchView.OnQueryTextListener, ItemSelectionListener<User> {
public class SelectModeratorsFragment extends Fragment implements ItemSelectionListener<User> {

private UserServices userServices;
private RecyclerView ureportersList;

private UreportersAdapter ureportersAdapter;

private ValueEventListener userEventListener;
private InfiniteFireLinearRecyclerView ureportersList;

@Nullable
@Override
Expand All @@ -52,83 +43,33 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

setupObjects();
setupView(view);
loadMasterModerators();
}

@Override
public void onDestroyView() {
super.onDestroyView();
if(userEventListener != null) userServices.removeCountryCodeListener(userEventListener);
loadCountryModerators();
}

private void setupView(View view) {
ureportersList = (RecyclerView) view.findViewById(R.id.ureportersList);
ureportersList = (InfiniteFireLinearRecyclerView) view.findViewById(R.id.ureportersList);
ureportersList.setLayoutManager(new LinearLayoutManager(getActivity()));
}

private void setupObjects() {
userServices = new UserServices();
}

private void loadMasterModerators() {
userServices.loadMasterModerators(new UserServices.OnLoadAllUsersListener() {
@Override
public void onLoadAllUsers(List<User> masterModerators) {
loadCountryModerators(masterModerators);
}
});
private void loadCountryModerators() {
userServices.loadCountryModerators(this::loadUsers);
}

private void loadCountryModerators(final List<User> masterModerators) {
userServices.loadCountryModerators(new UserServices.OnLoadAllUsersListener() {
@Override
public void onLoadAllUsers(final List<User> countryModerators) {
loadUsersByCountryCode(masterModerators, countryModerators);
}
});
}
private void loadUsers(List<User> moderators) {
InfiniteFireArray<User> usersFireArray = new InfiniteFireArray<>(User.class
, userServices.getUserCountryProgramQuery(), 30, 30, false, false);

private void loadUsersByCountryCode(final List<User> masterModerators, final List<User> countryModerators) {
userEventListener = userServices.loadByCountryCode(new UserServices.OnLoadAllUsersListener() {
@Override
public void onLoadAllUsers(List<User> users) {
users.removeAll(masterModerators);
setupAdapter(users, countryModerators);
}
});
}

private void setupAdapter(List<User> users, List<User> moderators) {
ureportersAdapter = new UreportersAdapter(users);
UreportersInfiniteAdapter ureportersAdapter = new UreportersInfiniteAdapter(usersFireArray);
ureportersAdapter.setHasStableIds(true);
ureportersAdapter.setSelectionEnabled(true, null, moderators);
ureportersAdapter.setItemSelectionListener(this);
ureportersList.setAdapter(ureportersAdapter);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

SearchManager searchManager = new SearchManager(getActivity());
searchManager.addSearchView(menu, R.string.search_hint_users, this, this);
}

@Override
public boolean onQueryTextSubmit(String query) {
ureportersAdapter.search(query);
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
ureportersAdapter.search(newText);
return false;
}

@Override
public boolean onClose() {
ureportersAdapter.clearSearch();
return false;
ureportersList.setAdapter(ureportersAdapter);
ureportersList.setInfiniteFireArray(usersFireArray);
}

@Override
Expand All @@ -145,14 +86,11 @@ private void displayToast(@StringRes int message) {
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
}

private Firebase.CompletionListener onUpdateUserCompletionListener = new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError == null) {
displayToast(R.string.message_success_user_update);
} else {
displayToast(R.string.error_update_user);
}
private Firebase.CompletionListener onUpdateUserCompletionListener = (firebaseError, firebase) -> {
if (firebaseError == null) {
displayToast(R.string.message_success_user_update);
} else {
displayToast(R.string.error_update_user);
}
};
}
2 changes: 1 addition & 1 deletion app/src/main/java/in/ureport/fragments/SignUpFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private User createUser() {
user.setCountryProgram(CountryProgramManager.getCountryProgramForCode(countryCode).getCode());

UserGender userGender = (UserGender)gender.getAdapter().getItem(gender.getSelectedItemPosition());
user.setGender(userGender.getGender());
user.setGenderAsEnum(userGender.getGender());
return user;
}

Expand Down
32 changes: 16 additions & 16 deletions app/src/main/java/in/ureport/fragments/StoriesListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import in.ureport.models.News;
import in.ureport.models.Story;
import in.ureport.models.User;
import in.ureport.models.holders.StoryHolder;
import in.ureport.network.ContributionServices;
import in.ureport.network.Response;
import in.ureport.network.StoryServices;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class StoriesListFragment extends Fragment implements StoriesAdapter.OnSt

private User user;
private ArrayList<News> newsList;
private Map<String, Story> storiesLoaded;
private Map<String, StoryHolder> storiesLoaded;
protected boolean publicType = true;

private OnPublishStoryListener onPublishStoryListener;
Expand Down Expand Up @@ -254,48 +255,47 @@ private boolean needsUserPublish() {
}

@Override
public void loadStoryData(final Story story, OnStoryUpdatedListener onStoryUpdatedListener) {
public StoryHolder loadStoryData(final Story story) {
if (storiesLoaded.containsKey(story.getKey())) {
Story storyLoaded = storiesLoaded.get(story.getKey());
StoryHolder storyLoaded = storiesLoaded.get(story.getKey());
copyDynamicData(storyLoaded, story);
onStoryUpdatedListener.onStoryUpdated(story);
return storyLoaded;
} else {
loadUsersFromStory(story, storyWithUser ->
contributionServices.getContributionCount(story, count -> {
story.setContributions(Long.valueOf(count).intValue());
loadStoryLikeCount(story, storyWithLikes -> {
storiesLoaded.put(story.getKey(), story);
onStoryUpdatedListener.onStoryUpdated(story);
});
}));
contributionServices.getContributionCount(story, storyWithContributions ->
loadStoryLikeCount(story, storyWithLikes -> {
storiesLoaded.put(story.getKey(), new StoryHolder(storyWithLikes));
storiesAdapter.updateStory(storyWithLikes);
})));
return null;
}
}

private void copyDynamicData(Story fromStory, Story toStory) {
private void copyDynamicData(StoryHolder fromStory, Story toStory) {
toStory.setUserObject(fromStory.getUserObject());
toStory.setLikes(fromStory.getLikes());
toStory.setContributions(fromStory.getContributions());
}

private void loadStoryLikeCount(Story story, final OnAfterStoryLoadedListener onAfterStoryLoadedListener) {
private void loadStoryLikeCount(Story story, final OnStoryUpdatedListener onStoryUpdatedListener) {
storyServices.loadStoryLikeCount(story, new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
super.onDataChange(dataSnapshot);
story.setLikes(dataSnapshot.exists() ? (int) dataSnapshot.getChildrenCount() : 0);
onAfterStoryLoadedListener.onAfterStoryLoaded(story);
onStoryUpdatedListener.onStoryUpdated(story);
}
});
}

private void loadUsersFromStory(final Story story, final OnAfterStoryLoadedListener onAfterStoryLoadedListener) {
private void loadUsersFromStory(final Story story, final OnStoryUpdatedListener onStoryUpdatedListener) {
userServices.getUser(story.getUser(), new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
if(user != null) {
story.setUserObject(user);
onAfterStoryLoadedListener.onAfterStoryLoaded(story);
onStoryUpdatedListener.onStoryUpdated(story);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void setPasswordVisibility() {
}

private void setUserGenderValue() {
UserGender userGender = new UserGender(getActivity(), user.getGender());
UserGender userGender = new UserGender(getActivity(), user.getGenderAsEnum());
ArrayAdapter<UserGender> adapter = ((ArrayAdapter<UserGender>) gender.getAdapter());
int position = adapter.getPosition(userGender);

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/in/ureport/helpers/ContactBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Contact buildContactWithFields(User user, Date registrationDate, String c
putValuesIfExists(formatDate(user.getBirthday()), contactFields, "birthday", "birthdate", "birth_day");
putValuesIfExists(getBornFormatted(user), contactFields, "year_of_birth", "born", "birth_year");
putValuesIfExists(getAgeFormatted(user), contactFields, "age");
putValuesIfExists(user.getGender().toString(), contactFields, "gender");
putValuesIfExists(user.getGender(), contactFields, "gender");
putValuesIfExists(user.getState(), contactFields, possibleStates);
putValuesIfExists(user.getDistrict(), contactFields, possibleDistricts);
putValuesIfExists(countryCode, contactFields, "country");
Expand Down
Loading

0 comments on commit 17aedb3

Please sign in to comment.