-
Notifications
You must be signed in to change notification settings - Fork 191
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
ProteusGridLayoutManager and ViewPager Example implemented #166
base: master
Are you sure you want to change the base?
Changes from all commits
52750af
fa58671
700520c
037e3c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"0": { | ||
"name": "John Doe", | ||
"name": "Ravi Ranjan", | ||
"location": { | ||
"country": "India", | ||
"city": "Bengaluru", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
import androidx.appcompat.app.AlertDialog; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.core.content.ContextCompat; | ||
import androidx.recyclerview.widget.LinearSnapHelper; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
public class ProteusActivity extends AppCompatActivity implements ProteusManager.Listener { | ||
|
||
|
@@ -216,6 +219,44 @@ void render() { | |
|
||
// Add the inflated view to the container | ||
container.addView(view.getAsView()); | ||
|
||
|
||
|
||
Comment on lines
+223
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these excess new lines be removed? |
||
LinearSnapHelper snapHelper = new LinearSnapHelper() { | ||
@Override | ||
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) { | ||
View centerView = findSnapView(layoutManager); | ||
if (centerView == null) | ||
return RecyclerView.NO_POSITION; | ||
|
||
int position = layoutManager.getPosition(centerView); | ||
int targetPosition = -1; | ||
if (layoutManager.canScrollHorizontally()) { | ||
if (velocityX < 0) { | ||
targetPosition = position - 1; | ||
} else { | ||
targetPosition = position + 1; | ||
} | ||
} | ||
|
||
if (layoutManager.canScrollVertically()) { | ||
if (velocityY < 0) { | ||
targetPosition = position - 1; | ||
} else { | ||
targetPosition = position + 1; | ||
} | ||
} | ||
|
||
final int firstItem = 0; | ||
final int lastItem = layoutManager.getItemCount() - 1; | ||
targetPosition = Math.min(lastItem, Math.max(targetPosition, firstItem)); | ||
return targetPosition; | ||
} | ||
}; | ||
|
||
View recyclerView = view.getViewManager().findViewById("rc_view"); | ||
snapHelper.attachToRecyclerView((RecyclerView) recyclerView); | ||
|
||
} | ||
|
||
void reload() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.flipkart.android.proteus.support.v7.adapter.SimpleListAdapter; | ||
import com.flipkart.android.proteus.support.v7.layoutmanager.LayoutManagerBuilder; | ||
import com.flipkart.android.proteus.support.v7.layoutmanager.LayoutManagerFactory; | ||
import com.flipkart.android.proteus.support.v7.layoutmanager.ProteusGridLayoutManager; | ||
import com.flipkart.android.proteus.support.v7.layoutmanager.ProteusLinearLayoutManager; | ||
import com.flipkart.android.proteus.support.v7.widget.RecyclerViewParser; | ||
|
||
|
@@ -42,6 +43,8 @@ public class RecyclerViewModule implements ProteusBuilder.Module { | |
static final String ADAPTER_SIMPLE_LIST = "SimpleListAdapter"; | ||
|
||
static final String LAYOUT_MANAGER_LINEAR = "LinearLayoutManager"; | ||
static final String LAYOUT_MANAGER_GRID = "GridLayoutManager"; | ||
|
||
|
||
@NonNull | ||
private final RecyclerViewAdapterFactory adapterFactory; | ||
|
@@ -175,7 +178,7 @@ public RecyclerViewModule build() { | |
} | ||
|
||
if (includeDefaultLayoutManagers) { | ||
registerDefaultLayoutManagers(); | ||
registerGridLayoutManagers(); | ||
} | ||
|
||
return new RecyclerViewModule(adapterFactory, layoutManagerFactory); | ||
|
@@ -188,5 +191,9 @@ private void registerDefaultAdapters() { | |
private void registerDefaultLayoutManagers() { | ||
register(LAYOUT_MANAGER_LINEAR, ProteusLinearLayoutManager.BUILDER); | ||
} | ||
Comment on lines
191
to
193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be deleted now? |
||
|
||
private void registerGridLayoutManagers() { | ||
register(LAYOUT_MANAGER_GRID, ProteusGridLayoutManager.BUILDER); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.flipkart.android.proteus.support.v7.layoutmanager; | ||
|
||
import android.content.Context; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.GridLayoutManager; | ||
|
||
import com.flipkart.android.proteus.support.v7.widget.ProteusRecyclerView; | ||
import com.flipkart.android.proteus.value.ObjectValue; | ||
|
||
public class ProteusGridLayoutManager extends GridLayoutManager { | ||
|
||
|
||
private static final String ATTRIBUTE_COL = "numCols"; | ||
private static final String ATTRIBUTE_ORIENTATION = "orientation"; | ||
private static final String ATTRIBUTE_REVERSE_LAYOUT = "reverse"; | ||
|
||
|
||
public static final LayoutManagerBuilder<ProteusGridLayoutManager> BUILDER = new LayoutManagerBuilder<ProteusGridLayoutManager>() { | ||
|
||
@NonNull | ||
@Override | ||
public ProteusGridLayoutManager create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { | ||
|
||
int orientation = config.getAsInteger(ATTRIBUTE_ORIENTATION, GridLayoutManager.VERTICAL); | ||
boolean reverseLayout = config.getAsBoolean(ATTRIBUTE_REVERSE_LAYOUT, false); | ||
|
||
int col = config.getAsInteger(ATTRIBUTE_COL, 1); | ||
|
||
|
||
|
||
return new ProteusGridLayoutManager(view.getContext(), col, orientation, reverseLayout); | ||
} | ||
}; | ||
|
||
|
||
public ProteusGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) { | ||
super(context, spanCount, orientation, reverseLayout); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
Comment on lines
+13
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the excess new lines be removed? |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please revert this?