Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no need to use JSONArray in Utils.loadProfiles() #3

Open
Zhuinden opened this issue Oct 16, 2017 · 11 comments
Open

There is no need to use JSONArray in Utils.loadProfiles() #3

Zhuinden opened this issue Oct 16, 2017 · 11 comments

Comments

@Zhuinden
Copy link

Zhuinden commented Oct 16, 2017

You can replace the JSONArray with TypeToken and use GSON to parse the List<Profile> directly.

public class Utils {
    @NonNull
    public static List<Profile> loadProfiles(Context context) {
        BufferedReader reader = null;
        try {
            AssetManager manager = context.getAssets();
            InputStream inputStream = manager.open("profiles.json");
            reader = new BufferedReader(new InputStreamReader(inputStream));
            Gson gson = new Gson(); // TODO dependency injection
            return gson.fromJson(reader, new TypeToken<ArrayList<Profile>>() {}.getType());
        } catch(Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            if(reader != null) {
                try {
                    reader.close();
                } catch(IOException e) {
                    // Ignore
                }
            }
        }
    }
}
@janishar
Copy link
Owner

@Zhuinden Sure

@scorlingonzalez
Copy link

hello brother, i am wondering why do i get repeated views whens swiping.

@janishar
Copy link
Owner

@scorlingonzalez It's added again for the demo purpose.

@scorlingonzalez
Copy link

what am trying to say is that i get repeated people while i swipe

@scorlingonzalez
Copy link

also for some reason i can get the image to show

@janishar
Copy link
Owner

@scorlingonzalez you are referring to the TinderSwipe project or tinder-swipe-v2?

@scorlingonzalez
Copy link

@janishar
Copy link
Owner

check this method:

    @SwipeOut
    private void onSwipedOut(){
        Log.d("EVENT", "onSwipedOut");
        mSwipeView.addView(this);
    }

remove this line: mSwipeView.addView(this)

It adds the view again if removed.

@scorlingonzalez
Copy link

@SwipeOut
public void onSwipedOut() {
mSwipeView.addView(this);
}

@scorlingonzalez
Copy link

i do have this method in the same format... it is usally random behavior for example i may get the same person twice in a row or just at random.. and also if let say an array has 3 people i can scroll like 15 or more time randomly repeating the people... do you think i can send you my code in facebook maybe u can help me out a bit please

@scorlingonzalez
Copy link

i delete that line but still same behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants