Commit fe086cdf authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #120 from pulsejet/marshmallow

Fix A6 crash, improve aesthetics, disallow DB queries on main thread
parents bd38c2aa 4e42bed8
...@@ -291,7 +291,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -291,7 +291,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
FragmentManager manager = getSupportFragmentManager(); FragmentManager manager = getSupportFragmentManager();
if (fragment instanceof FeedFragment) if (fragment instanceof FeedFragment)
manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
FragmentTransaction transaction = manager.beginTransaction(); FragmentTransaction transaction = manager.beginTransaction();
/* Animate only for ProfileFragment */
if (fragment instanceof ProfileFragment) {
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
}
transaction.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag()); transaction.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag());
transaction.addToBackStack(fragment.getTag()).commit(); transaction.addToBackStack(fragment.getTag()).commit();
} }
......
...@@ -54,9 +54,8 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> { ...@@ -54,9 +54,8 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
NewsArticle article = newsArticles.get(position); NewsArticle article = newsArticles.get(position);
Markwon.setMarkdown(holder.articleTitle, article.getTitle()); Markwon.setMarkdown(holder.articleTitle, article.getTitle());
holder.articleBody.setText(article.getBody().getBodyName()); holder.articleBody.setText(article.getBody().getBodyName());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = article.getPublished();
Date publishedDate = dateFormat.parse(article.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -66,9 +65,7 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> { ...@@ -66,9 +65,7 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.articlePublished.setText(displayFormat.format(publishedDate)); holder.articlePublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
e.printStackTrace();
}
Markwon.setMarkdown(holder.articleContent, article.getContent()); Markwon.setMarkdown(holder.articleContent, article.getContent());
} }
......
...@@ -51,9 +51,8 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap ...@@ -51,9 +51,8 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
PlacementBlogPost post = posts.get(position); PlacementBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle()); Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = post.getPublished();
Date publishedDate = dateFormat.parse(post.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -63,9 +62,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap ...@@ -63,9 +62,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.postPublished.setText(displayFormat.format(publishedDate)); holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent()); Markwon.setMarkdown(holder.postContent, post.getContent());
} }
......
...@@ -51,9 +51,8 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte ...@@ -51,9 +51,8 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
TrainingBlogPost post = posts.get(position); TrainingBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle()); Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = post.getPublished();
Date publishedDate = dateFormat.parse(post.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -63,9 +62,7 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte ...@@ -63,9 +62,7 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.postPublished.setText(displayFormat.format(publishedDate)); holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent()); Markwon.setMarkdown(holder.postContent, post.getContent());
} }
......
...@@ -18,7 +18,7 @@ public abstract class AppDatabase extends RoomDatabase { ...@@ -18,7 +18,7 @@ public abstract class AppDatabase extends RoomDatabase {
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "database") Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "database")
// allow queries on the main thread. // allow queries on the main thread.
// Don't do this on a real app! See PersistenceBasicSample for an example. // Don't do this on a real app! See PersistenceBasicSample for an example.
.allowMainThreadQueries() // .allowMainThreadQueries()
.build(); .build();
} }
return INSTANCE; return INSTANCE;
......
...@@ -6,7 +6,7 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,7 +6,7 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.Map; import java.sql.Timestamp;
@Entity(tableName = "news") @Entity(tableName = "news")
...@@ -33,13 +33,13 @@ public class NewsArticle { ...@@ -33,13 +33,13 @@ public class NewsArticle {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
@ColumnInfo(name = "body") @ColumnInfo(name = "body")
@SerializedName("body") @SerializedName("body")
private Body body; private Body body;
public NewsArticle(String articleID, String link, String title, String content, String published, Body body) { public NewsArticle(String articleID, String link, String title, String content, Timestamp published, Body body) {
this.articleID = articleID; this.articleID = articleID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -80,11 +80,11 @@ public class NewsArticle { ...@@ -80,11 +80,11 @@ public class NewsArticle {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
......
...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "placementBlogPosts") @Entity(tableName = "placementBlogPosts")
public class PlacementBlogPost { public class PlacementBlogPost {
...@@ -31,9 +33,9 @@ public class PlacementBlogPost { ...@@ -31,9 +33,9 @@ public class PlacementBlogPost {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
public PlacementBlogPost(String postID, String link, String title, String content, String published) { public PlacementBlogPost(String postID, String link, String title, String content, Timestamp published) {
this.postID = postID; this.postID = postID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -73,11 +75,11 @@ public class PlacementBlogPost { ...@@ -73,11 +75,11 @@ public class PlacementBlogPost {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
} }
...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "trainingBlogPosts") @Entity(tableName = "trainingBlogPosts")
public class TrainingBlogPost { public class TrainingBlogPost {
...@@ -31,9 +33,9 @@ public class TrainingBlogPost { ...@@ -31,9 +33,9 @@ public class TrainingBlogPost {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
public TrainingBlogPost(String postID, String link, String title, String content, String published) { public TrainingBlogPost(String postID, String link, String title, String content, Timestamp published) {
this.postID = postID; this.postID = postID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -73,11 +75,11 @@ public class TrainingBlogPost { ...@@ -73,11 +75,11 @@ public class TrainingBlogPost {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
} }
...@@ -93,12 +93,7 @@ public class BodyFragment extends Fragment { ...@@ -93,12 +93,7 @@ public class BodyFragment extends Fragment {
/* Initialize */ /* Initialize */
appDatabase = AppDatabase.getAppDatabase(getContext()); appDatabase = AppDatabase.getAppDatabase(getContext());
Body[] inLocalDb = appDatabase.dbDao().getBody(min_body.getBodyID()); new getDbBody().execute(min_body.getBodyID());
if (inLocalDb.length > 0) {
displayBody(inLocalDb[0]);
} else {
updateBody();
}
bodySwipeRefreshLayout=getActivity().findViewById(R.id.body_swipe_refresh_layout); bodySwipeRefreshLayout=getActivity().findViewById(R.id.body_swipe_refresh_layout);
bodySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { bodySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
...@@ -116,7 +111,7 @@ public class BodyFragment extends Fragment { ...@@ -116,7 +111,7 @@ public class BodyFragment extends Fragment {
if (response.isSuccessful()) { if (response.isSuccessful()) {
Body body = response.body(); Body body = response.body();
appDatabase.dbDao().insertBody(body); new insertDbBody().execute(body);
displayBody(body); displayBody(body);
bodySwipeRefreshLayout.setRefreshing(false); bodySwipeRefreshLayout.setRefreshing(false);
...@@ -209,6 +204,7 @@ public class BodyFragment extends Fragment { ...@@ -209,6 +204,7 @@ public class BodyFragment extends Fragment {
EventFragment eventFragment = new EventFragment(); EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle); eventFragment.setArguments(bundle);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
ft.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag()); ft.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
ft.addToBackStack(eventFragment.getTag()); ft.addToBackStack(eventFragment.getTag());
ft.commit(); ft.commit();
...@@ -226,6 +222,30 @@ public class BodyFragment extends Fragment { ...@@ -226,6 +222,30 @@ public class BodyFragment extends Fragment {
} }
} }
private class insertDbBody extends AsyncTask<Body, Void, Integer> {
@Override
protected Integer doInBackground(Body... body) {
appDatabase.dbDao().insertBody(body[0]);
return 1;
}
}
private class getDbBody extends AsyncTask<String, Void, Body[]> {
@Override
protected Body[] doInBackground(String... id) {
return appDatabase.dbDao().getBody(min_body.getBodyID());
}
@Override
protected void onPostExecute(Body[] result) {
if (result.length > 0) {
displayBody(result[0]);
} else {
updateBody();
}
}
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
......
...@@ -119,6 +119,7 @@ public class EventFragment extends BaseFragment { ...@@ -119,6 +119,7 @@ public class EventFragment extends BaseFragment {
Body body = bodyList.get(position); Body body = bodyList.get(position);
BodyFragment bodyFragment = BodyFragment.newInstance(body); BodyFragment bodyFragment = BodyFragment.newInstance(body);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag()); ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
ft.addToBackStack(bodyFragment.getTag()); ft.addToBackStack(bodyFragment.getTag());
ft.commit(); ft.commit();
......
...@@ -64,6 +64,7 @@ public class FeedFragment extends BaseFragment { ...@@ -64,6 +64,7 @@ public class FeedFragment extends BaseFragment {
AddEventFragment addEventFragment = new AddEventFragment(); AddEventFragment addEventFragment = new AddEventFragment();
addEventFragment.setArguments(getArguments()); addEventFragment.setArguments(getArguments());
FragmentTransaction ft = getChildFragmentManager().beginTransaction(); FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
ft.replace(R.id.relative_layout, addEventFragment); ft.replace(R.id.relative_layout, addEventFragment);
ft.addToBackStack("addEvent"); ft.addToBackStack("addEvent");
ft.commit(); ft.commit();
...@@ -146,6 +147,7 @@ public class FeedFragment extends BaseFragment { ...@@ -146,6 +147,7 @@ public class FeedFragment extends BaseFragment {
eventFragment.setArguments(bundle); eventFragment.setArguments(bundle);
FragmentManager manager = getActivity().getSupportFragmentManager(); FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction(); FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag()); transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
transaction.addToBackStack(eventFragment.getTag()).commit(); transaction.addToBackStack(eventFragment.getTag()).commit();
} }
......
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="1280"
android:valueTo="0"
android:duration="400"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="-1280"
android:valueTo="0"
android:duration="400"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="-1280"
android:duration="400"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="1280"
android:duration="400"/>
</set>
\ No newline at end of file
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/feed_recycler_view" android:id="@+id/feed_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:paddingTop="8dp" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/news_recycler_view" android:id="@+id/news_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:paddingTop="8dp" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout> </RelativeLayout>
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/placement_feed_recycler_view" android:id="@+id/placement_feed_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:paddingTop="8dp" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout> </RelativeLayout>
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/training_feed_recycler_view" android:id="@+id/training_feed_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:paddingTop="8dp" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout> </RelativeLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment