Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
11aff4b6
Commit
11aff4b6
authored
Jan 04, 2019
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite BodyFragment to be fully RecylerView
parent
538ed195
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
771 additions
and
557 deletions
+771
-557
app/build.gradle
app/build.gradle
+1
-0
app/src/main/java/app/insti/Constants.java
app/src/main/java/app/insti/Constants.java
+3
-0
app/src/main/java/app/insti/Utils.java
app/src/main/java/app/insti/Utils.java
+3
-2
app/src/main/java/app/insti/adapter/CardAdapter.java
app/src/main/java/app/insti/adapter/CardAdapter.java
+83
-40
app/src/main/java/app/insti/fragment/BodyFragment.java
app/src/main/java/app/insti/fragment/BodyFragment.java
+0
-274
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
+351
-0
app/src/main/java/app/insti/fragment/EventFragment.java
app/src/main/java/app/insti/fragment/EventFragment.java
+1
-1
app/src/main/java/app/insti/utils/BodyHeadCard.java
app/src/main/java/app/insti/utils/BodyHeadCard.java
+39
-0
app/src/main/java/app/insti/utils/BodyHeadViewHolder.java
app/src/main/java/app/insti/utils/BodyHeadViewHolder.java
+109
-0
app/src/main/java/app/insti/utils/TitleCard.java
app/src/main/java/app/insti/utils/TitleCard.java
+32
-0
app/src/main/res/layout/fragment_body.xml
app/src/main/res/layout/fragment_body.xml
+95
-240
app/src/main/res/layout/fragment_body_fragment_new.xml
app/src/main/res/layout/fragment_body_fragment_new.xml
+40
-0
app/src/main/res/layout/title_card.xml
app/src/main/res/layout/title_card.xml
+14
-0
No files found.
app/build.gradle
View file @
11aff4b6
...
...
@@ -57,5 +57,6 @@ dependencies {
implementation
"me.relex:circleindicator:${circleIndicatorVersion}"
implementation
"com.google.android:flexbox:${flexboxVersion}"
implementation
"io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:${sectionedRecyclerViewVersion}"
implementation
'com.android.support:support-v4:28.0.0'
}
apply
plugin:
'com.google.gms.google-services'
app/src/main/java/app/insti/Constants.java
View file @
11aff4b6
...
...
@@ -54,6 +54,9 @@ public class Constants {
public
static
final
String
DATA_TYPE_NEWS
=
"newsentry"
;
public
static
final
String
DATA_TYPE_PT
=
"blogentry"
;
public
static
final
String
CARD_TYPE_TITLE
=
"card_type_title"
;
public
static
final
String
CARD_TYPE_BODY_HEAD
=
"card_type_body_head"
;
/* Map */
public
static
final
double
MAP_Xn
=
19.134417
,
MAP_Yn
=
72.901229
,
MAP_Zn
=
1757
,
MAP_Zyn
=
501
;
public
static
final
double
[]
MAP_WEIGHTS_X
=
{-
11.392001766454612
,
-
36.31634553309953
,
73.91269388324432
,
-
24.14021153064087
,
3.4508817531539115
,
-
0.1462262375477863
,
5.532505074667804
,
-
1.542391995870977
,
36.14211738142935
};
...
...
app/src/main/java/app/insti/Utils.java
View file @
11aff4b6
...
...
@@ -31,6 +31,7 @@ import app.insti.api.model.Event;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.User
;
import
app.insti.fragment.BodyFragment
;
import
app.insti.fragment.BodyFragmentNew
;
import
app.insti.fragment.EventFragment
;
import
app.insti.fragment.TransitionTargetChild
;
import
app.insti.fragment.TransitionTargetFragment
;
...
...
@@ -139,11 +140,11 @@ public final class Utils {
.
commit
();
}
public
static
BodyFragment
getBodyFragment
(
Body
body
,
boolean
sharedElements
)
{
public
static
BodyFragment
New
getBodyFragment
(
Body
body
,
boolean
sharedElements
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
bundle
.
putBoolean
(
Constants
.
NO_SHARED_ELEM
,
!
sharedElements
);
BodyFragment
bodyFragment
=
new
BodyFragment
();
BodyFragment
New
bodyFragment
=
new
BodyFragmentNew
();
bodyFragment
.
setArguments
(
bundle
);
return
bodyFragment
;
}
...
...
app/src/main/java/app/insti/adapter/CardAdapter.java
View file @
11aff4b6
...
...
@@ -4,6 +4,7 @@ import android.content.Context;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v7.widget.CardView
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
...
...
@@ -16,11 +17,14 @@ import com.squareup.picasso.RequestCreator;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.R
;
import
app.insti.Utils
;
import
app.insti.interfaces.CardInterface
;
import
app.insti.utils.BodyHeadCard
;
import
app.insti.utils.BodyHeadViewHolder
;
public
abstract
class
CardAdapter
<
T
extends
CardInterface
>
extends
RecyclerView
.
Adapter
<
CardAdapter
<
T
>
.
ViewHolder
>
{
public
abstract
class
CardAdapter
<
T
extends
CardInterface
>
extends
RecyclerView
.
Adapter
<
RecyclerView
.
ViewHolder
>
{
private
List
<
T
>
tList
;
private
Fragment
mFragment
;
...
...
@@ -45,12 +49,23 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
@Override
@NonNull
public
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
viewGroup
,
final
int
i
)
{
public
RecyclerView
.
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
viewGroup
,
final
int
viewType
)
{
Context
context
=
viewGroup
.
getContext
();
LayoutInflater
inflater
=
LayoutInflater
.
from
(
context
);
if
(
viewType
==
2
)
{
View
titleView
=
inflater
.
inflate
(
R
.
layout
.
title_card
,
viewGroup
,
false
);
return
new
TitleViewHolder
(
titleView
);
}
if
(
viewType
==
4
)
{
View
bodyView
=
inflater
.
inflate
(
R
.
layout
.
fragment_body
,
viewGroup
,
false
);
return
new
BodyHeadViewHolder
(
bodyView
);
}
View
postView
=
inflater
.
inflate
(
R
.
layout
.
feed_card
,
viewGroup
,
false
);
final
ViewHolder
postViewHolder
=
new
ViewHolder
(
postView
);
final
CardViewHolder
postViewHolder
=
new
Card
ViewHolder
(
postView
);
postView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -63,50 +78,63 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
}
@Override
public
void
onBindViewHolder
(
@NonNull
ViewHolder
viewHolder
,
int
i
)
{
T
t
=
tList
.
get
(
i
);
viewHolder
.
title
.
setText
(
t
.
getTitle
());
viewHolder
.
subtitle
.
setText
(
t
.
getSubtitle
());
// Set transition names
viewHolder
.
avatar
.
setTransitionName
(
uid
+
Integer
.
toString
((
int
)
t
.
getId
())
+
"_sharedAvatar"
);
if
(
getBigImageUrl
(
t
)
!=
null
)
{
// Show big image, hide avatar
viewHolder
.
bigPicture
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
bigPicture
.
setTransitionName
(
uid
+
Integer
.
toString
((
int
)
t
.
getId
())
+
"_sharedBigPicture"
);
viewHolder
.
avatar
.
setVisibility
(
View
.
GONE
);
// Load big image with low resolution as avatar
Utils
.
loadImageWithPlaceholder
(
viewHolder
.
bigPicture
,
getBigImageUrl
(
t
));
}
else
{
// Build basic request
RequestCreator
requestCreator
;
if
(
t
.
getAvatarUrl
()
!=
null
)
requestCreator
=
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
t
.
getAvatarUrl
()));
else
if
(
getAvatarPlaceholder
(
t
)
!=
0
)
{
requestCreator
=
Picasso
.
get
().
load
(
getAvatarPlaceholder
(
t
));
}
else
{
public
void
onBindViewHolder
(
@NonNull
RecyclerView
.
ViewHolder
holder
,
int
i
)
{
switch
(
holder
.
getItemViewType
())
{
case
0
:
CardViewHolder
viewHolder
=
(
CardViewHolder
)
holder
;
T
t
=
tList
.
get
(
i
);
viewHolder
.
title
.
setText
(
t
.
getTitle
());
viewHolder
.
subtitle
.
setText
(
t
.
getSubtitle
());
// Set transition names
viewHolder
.
avatar
.
setTransitionName
(
uid
+
Integer
.
toString
((
int
)
t
.
getId
())
+
"_sharedAvatar"
);
if
(
getBigImageUrl
(
t
)
!=
null
)
{
// Show big image, hide avatar
viewHolder
.
bigPicture
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
bigPicture
.
setTransitionName
(
uid
+
Integer
.
toString
((
int
)
t
.
getId
())
+
"_sharedBigPicture"
);
viewHolder
.
avatar
.
setVisibility
(
View
.
GONE
);
// Load big image with low resolution as avatar
Utils
.
loadImageWithPlaceholder
(
viewHolder
.
bigPicture
,
getBigImageUrl
(
t
));
}
else
{
// Build basic request
RequestCreator
requestCreator
;
if
(
t
.
getAvatarUrl
()
!=
null
)
requestCreator
=
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
t
.
getAvatarUrl
()));
else
if
(
getAvatarPlaceholder
(
t
)
!=
0
)
{
requestCreator
=
Picasso
.
get
().
load
(
getAvatarPlaceholder
(
t
));
}
else
{
return
;
}
// Check if we have a placeholder
if
(
getAvatarPlaceholder
(
t
)
!=
0
)
{
requestCreator
.
placeholder
(
getAvatarPlaceholder
(
t
));
}
// Load the image
requestCreator
.
into
(
viewHolder
.
avatar
);
}
return
;
case
2
:
TitleViewHolder
titleViewHolder
=
(
TitleViewHolder
)
holder
;
titleViewHolder
.
title
.
setText
(
tList
.
get
(
i
).
getTitle
());
return
;
case
4
:
((
BodyHeadCard
)
tList
.
get
(
i
)).
bindView
((
BodyHeadViewHolder
)
holder
,
mFragment
);
return
;
}
// Check if we have a placeholder
if
(
getAvatarPlaceholder
(
t
)
!=
0
)
{
requestCreator
.
placeholder
(
getAvatarPlaceholder
(
t
));
}
// Load the image
requestCreator
.
into
(
viewHolder
.
avatar
);
}
}
public
class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
public
class
Card
ViewHolder
extends
RecyclerView
.
ViewHolder
{
private
ImageView
avatar
;
private
TextView
title
;
private
TextView
subtitle
;
private
ImageView
bigPicture
;
public
ViewHolder
(
View
itemView
)
{
public
Card
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
avatar
=
itemView
.
findViewById
(
R
.
id
.
object_picture
);
...
...
@@ -116,10 +144,25 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
}
}
public
class
TitleViewHolder
extends
RecyclerView
.
ViewHolder
{
private
TextView
title
;
public
TitleViewHolder
(
View
itemView
)
{
super
(
itemView
);
title
=
itemView
.
findViewById
(
R
.
id
.
title_text
);
}
}
@Override
public
int
getItemViewType
(
int
position
)
{
if
(
position
==
0
)
return
1
;
else
return
2
;
if
(
tList
.
get
(
position
)
==
null
)
return
0
;
if
(
tList
.
get
(
position
).
getSubtitle
().
equals
(
Constants
.
CARD_TYPE_TITLE
))
{
return
2
;
}
else
if
(
tList
.
get
(
position
).
getSubtitle
().
equals
(
Constants
.
CARD_TYPE_BODY_HEAD
))
{
return
4
;
}
return
0
;
}
@Override
...
...
app/src/main/java/app/insti/fragment/BodyFragment.java
View file @
11aff4b6
This diff is collapsed.
Click to expand it.
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
0 → 100644
View file @
11aff4b6
This diff is collapsed.
Click to expand it.
app/src/main/java/app/insti/fragment/EventFragment.java
View file @
11aff4b6
...
...
@@ -100,7 +100,7 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
* @param count integer count to show in the badge
* @return spannable to be used as view.setText(spannable)
*/
static
Spannable
getCountBadgeSpannable
(
String
text
,
Integer
count
)
{
public
static
Spannable
getCountBadgeSpannable
(
String
text
,
Integer
count
)
{
// Check for nulls
if
(
count
==
null
)
return
new
SpannableString
(
text
);
...
...
app/src/main/java/app/insti/utils/BodyHeadCard.java
0 → 100644
View file @
11aff4b6
package
app.insti.utils
;
import
android.support.v4.app.Fragment
;
import
app.insti.Constants
;
import
app.insti.api.model.Body
;
import
app.insti.interfaces.CardInterface
;
public
class
BodyHeadCard
implements
CardInterface
{
private
Body
body
;
public
BodyHeadCard
(
Body
mBody
)
{
body
=
mBody
;
}
@Override
public
long
getId
()
{
return
0
;
}
@Override
public
String
getTitle
()
{
return
null
;
}
@Override
public
String
getSubtitle
()
{
return
Constants
.
CARD_TYPE_BODY_HEAD
;
}
@Override
public
String
getAvatarUrl
()
{
return
null
;
}
public
void
bindView
(
BodyHeadViewHolder
viewHolder
,
Fragment
fragment
)
{
viewHolder
.
bindView
(
body
,
fragment
);
}
}
app/src/main/java/app/insti/utils/BodyHeadViewHolder.java
0 → 100644
View file @
11aff4b6
package
app.insti.utils
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.support.v4.app.Fragment
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageButton
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
app.insti.R
;
import
app.insti.ShareURLMaker
;
import
app.insti.Utils
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Body
;
import
app.insti.fragment.EventFragment
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
ru.noties.markwon.Markwon
;
public
class
BodyHeadViewHolder
extends
RecyclerView
.
ViewHolder
{
private
TextView
bodyName
;
private
TextView
bodySubtitle
;
private
TextView
bodyDescription
;
private
ImageButton
webBodyButton
;
private
ImageButton
shareBodyButton
;
private
final
Button
followButton
;
public
BodyHeadViewHolder
(
View
itemView
)
{
super
(
itemView
);
bodyName
=
itemView
.
findViewById
(
R
.
id
.
body_name
);
bodySubtitle
=
itemView
.
findViewById
(
R
.
id
.
body_subtitle
);
bodyDescription
=
itemView
.
findViewById
(
R
.
id
.
body_description
);
webBodyButton
=
itemView
.
findViewById
(
R
.
id
.
web_body_button
);
shareBodyButton
=
itemView
.
findViewById
(
R
.
id
.
share_body_button
);
followButton
=
itemView
.
findViewById
(
R
.
id
.
follow_button
);
}
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
;
}
Markwon
.
setMarkdown
(
bodyDescription
,
body
.
getBodyDescription
());
/* Check if user is already following
* Initialize follow button */
followButton
.
setBackgroundColor
(
fragment
.
getResources
().
getColor
(
body
.
getBodyUserFollows
()
?
R
.
color
.
colorAccent
:
R
.
color
.
colorWhite
));
followButton
.
setText
(
EventFragment
.
getCountBadgeSpannable
(
"FOLLOW"
,
body
.
getBodyFollowersCount
()));
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
);
followButton
.
setBackgroundColor
(
fragment
.
getResources
().
getColor
(
body
.
getBodyUserFollows
()
?
R
.
color
.
colorAccent
:
R
.
color
.
colorWhite
));
followButton
.
setText
(
EventFragment
.
getCountBadgeSpannable
(
"FOLLOW"
,
body
.
getBodyFollowersCount
()));
}
}
@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"
));
}
});
}
}
app/src/main/java/app/insti/utils/TitleCard.java
0 → 100644
View file @
11aff4b6
package
app.insti.utils
;
import
app.insti.Constants
;
import
app.insti.interfaces.CardInterface
;
public
class
TitleCard
implements
CardInterface
{
private
String
title
;
public
TitleCard
(
String
mTitle
)
{
title
=
mTitle
;
}
@Override
public
long
getId
()
{
return
(
getSubtitle
()
+
getTitle
()).
hashCode
();
}
@Override
public
String
getTitle
()
{
return
title
;
}
@Override
public
String
getSubtitle
()
{
return
Constants
.
CARD_TYPE_TITLE
;
}
@Override
public
String
getAvatarUrl
()
{
return
null
;
}
}
app/src/main/res/layout/fragment_body.xml
View file @
11aff4b6
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/fragment_body_fragment_new.xml
0 → 100644
View file @
11aff4b6
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
tools:context=
".fragment.BodyFragmentNew"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<ImageView
android:id=
"@+id/body_picture"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:adjustViewBounds=
"true"
android:scaleType=
"fitCenter"
android:transitionName=
"sharedAvatar"
/>
<android.support.v7.widget.RecyclerView
android:id=
"@+id/body_recycler_view"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:id=
"@+id/loadingPanel"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:gravity=
"center"
>
<ProgressBar
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:indeterminate=
"true"
android:theme=
"@style/BlueAccent"
/>
</RelativeLayout>
</FrameLayout>
\ No newline at end of file
app/src/main/res/layout/title_card.xml
0 → 100644
View file @
11aff4b6
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:id=
"@+id/title_text"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"15dp"
android:fontFamily=
"sans-serif-light"
android:textSize=
"20sp"
/>
</LinearLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment