Browse Source

More tiny cleanups

pull/24/head
Ezerous 8 years ago
parent
commit
ad06299dc3
  1. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java
  2. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java
  3. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  4. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java
  5. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  6. 2
      app/src/main/res/values/strings.xml

8
app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java

@ -51,12 +51,6 @@ public abstract class BaseFragment extends Fragment {
Report.d(TAG, "onStop"); Report.d(TAG, "onStop");
} }
@Override
public void onDestroy() {
super.onDestroy();
cancelTask();
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@ -75,8 +69,6 @@ public abstract class BaseFragment extends Fragment {
fragmentInteractionListener = null; fragmentInteractionListener = null;
} }
protected abstract void cancelTask();
/** /**
* This interface MUST be extended by the fragment subclass AND implemented by * This interface MUST be extended by the fragment subclass AND implemented by
* the activity that contains it, to allow communication upon interaction, * the activity that contains it, to allow communication upon interaction,

7
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.main.forum; package gr.thmmy.mthmmy.activities.main.forum;
import android.content.Context;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -18,10 +19,12 @@ import gr.thmmy.mthmmy.data.TopicSummary;
* specified {@link ForumFragment.ForumFragmentInteractionListener}. * specified {@link ForumFragment.ForumFragmentInteractionListener}.
*/ */
class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> { class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> {
private final Context context;
private final List<TopicSummary> recentList; private final List<TopicSummary> recentList;
private final ForumFragment.ForumFragmentInteractionListener mListener; private final ForumFragment.ForumFragmentInteractionListener mListener;
ForumAdapter(List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) { ForumAdapter(Context context, List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) {
this.context = context;
this.recentList = topicSummaryList; this.recentList = topicSummaryList;
mListener = (ForumFragment.ForumFragmentInteractionListener)listener; mListener = (ForumFragment.ForumFragmentInteractionListener)listener;
} }
@ -40,7 +43,7 @@ class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> {
holder.mTitleView.setText(recentList.get(position).getTitle()); holder.mTitleView.setText(recentList.get(position).getTitle());
holder.mDateTimeView.setText(recentList.get(position).getDateTimeModified()); holder.mDateTimeView.setText(recentList.get(position).getDateTimeModified());
holder.mUserView.setText("by " + recentList.get(position).getLastUser()); holder.mUserView.setText(context.getString(R.string.byUser, recentList.get(position).getLastUser()));
holder.topic = recentList.get(position); holder.topic = recentList.get(position);

15
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java

@ -58,8 +58,6 @@ public class ForumFragment extends BaseFragment
/** /**
* Use ONLY this factory method to create a new instance of * Use ONLY this factory method to create a new instance of
* this fragment using the provided parameters. * this fragment using the provided parameters.
*
* @param sectionNumber
* @return A new instance of fragment Forum. * @return A new instance of fragment Forum.
*/ */
public static ForumFragment newInstance(int sectionNumber) { public static ForumFragment newInstance(int sectionNumber) {
@ -80,9 +78,11 @@ public class ForumFragment extends BaseFragment
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (sectionNumber == 1)//temp if (topicSummaries.isEmpty())
{ {
if (topicSummaries.isEmpty()) new ForumTask().execute(); forumTask =new ForumTask();
forumTask.execute();
} }
Report.d(TAG, "onActivityCreated"); Report.d(TAG, "onActivityCreated");
} }
@ -96,7 +96,7 @@ public class ForumFragment extends BaseFragment
// Set the adapter // Set the adapter
if (rootView instanceof RelativeLayout) { if (rootView instanceof RelativeLayout) {
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
forumAdapter = new ForumAdapter(topicSummaries, fragmentInteractionListener); forumAdapter = new ForumAdapter(getActivity(), topicSummaries, fragmentInteractionListener);
CustomRecyclerView recyclerView = (CustomRecyclerView) rootView.findViewById(R.id.list); CustomRecyclerView recyclerView = (CustomRecyclerView) rootView.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext()));
@ -120,7 +120,8 @@ public class ForumFragment extends BaseFragment
} }
@Override @Override
protected void cancelTask() { public void onDestroy() {
super.onDestroy();
if(forumTask!=null&&forumTask.getStatus()!= AsyncTask.Status.RUNNING) if(forumTask!=null&&forumTask.getStatus()!= AsyncTask.Status.RUNNING)
forumTask.cancel(true); forumTask.cancel(true);
} }
@ -157,7 +158,7 @@ public class ForumFragment extends BaseFragment
Report.d(TAG, "Network Error", e); Report.d(TAG, "Network Error", e);
return 1; return 1;
} catch (Exception e) { } catch (Exception e) {
Report.d(TAG, "ERROR", e); Report.d(TAG, "Exception", e);
return 2; return 2;
} }

7
app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.main.recent; package gr.thmmy.mthmmy.activities.main.recent;
import android.content.Context;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -18,10 +19,12 @@ import gr.thmmy.mthmmy.data.TopicSummary;
* specified {@link RecentFragment.RecentFragmentInteractionListener}. * specified {@link RecentFragment.RecentFragmentInteractionListener}.
*/ */
class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> { class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> {
private final Context context;
private final List<TopicSummary> recentList; private final List<TopicSummary> recentList;
private final RecentFragment.RecentFragmentInteractionListener mListener; private final RecentFragment.RecentFragmentInteractionListener mListener;
RecentAdapter(List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) { RecentAdapter(Context context, List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) {
this.context = context;
this.recentList = topicSummaryList; this.recentList = topicSummaryList;
mListener = (RecentFragment.RecentFragmentInteractionListener) listener; mListener = (RecentFragment.RecentFragmentInteractionListener) listener;
} }
@ -40,7 +43,7 @@ class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> {
holder.mTitleView.setText(recentList.get(position).getTitle()); holder.mTitleView.setText(recentList.get(position).getTitle());
holder.mDateTimeView.setText(recentList.get(position).getDateTimeModified()); holder.mDateTimeView.setText(recentList.get(position).getDateTimeModified());
holder.mUserView.setText("by " + recentList.get(position).getLastUser()); holder.mUserView.setText(context.getString(R.string.byUser, recentList.get(position).getLastUser()));
holder.topic = recentList.get(position); holder.topic = recentList.get(position);

13
app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java

@ -57,8 +57,6 @@ public class RecentFragment extends BaseFragment {
/** /**
* Use ONLY this factory method to create a new instance of * Use ONLY this factory method to create a new instance of
* this fragment using the provided parameters. * this fragment using the provided parameters.
*
* @param sectionNumber
* @return A new instance of fragment Recent. * @return A new instance of fragment Recent.
*/ */
public static RecentFragment newInstance(int sectionNumber) { public static RecentFragment newInstance(int sectionNumber) {
@ -79,15 +77,12 @@ public class RecentFragment extends BaseFragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (sectionNumber == 1)//temp
{
if (topicSummaries.isEmpty()) if (topicSummaries.isEmpty())
{ {
recentTask =new RecentTask(); recentTask =new RecentTask();
recentTask.execute(); recentTask.execute();
} }
}
Report.d(TAG, "onActivityCreated"); Report.d(TAG, "onActivityCreated");
} }
@ -101,7 +96,7 @@ public class RecentFragment extends BaseFragment {
// Set the adapter // Set the adapter
if (rootView instanceof RelativeLayout) { if (rootView instanceof RelativeLayout) {
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
recentAdapter = new RecentAdapter(topicSummaries, fragmentInteractionListener); recentAdapter = new RecentAdapter(getActivity(), topicSummaries, fragmentInteractionListener);
CustomRecyclerView recyclerView = (CustomRecyclerView) rootView.findViewById(R.id.list); CustomRecyclerView recyclerView = (CustomRecyclerView) rootView.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext()));
@ -126,11 +121,13 @@ public class RecentFragment extends BaseFragment {
} }
@Override @Override
protected void cancelTask() { public void onDestroy() {
super.onDestroy();
if(recentTask!=null&&recentTask.getStatus()!= AsyncTask.Status.RUNNING) if(recentTask!=null&&recentTask.getStatus()!= AsyncTask.Status.RUNNING)
recentTask.cancel(true); recentTask.cancel(true);
} }
public interface RecentFragmentInteractionListener extends FragmentInteractionListener { public interface RecentFragmentInteractionListener extends FragmentInteractionListener {
void onFragmentInteraction(TopicSummary topicSummary); void onFragmentInteraction(TopicSummary topicSummary);
} }
@ -162,7 +159,7 @@ public class RecentFragment extends BaseFragment {
Report.d(TAG, "Network Error", e); Report.d(TAG, "Network Error", e);
return 1; return 1;
} catch (Exception e) { } catch (Exception e) {
Report.d(TAG, "ERROR", e); Report.d(TAG, "Exception", e);
return 2; return 2;
} }

2
app/src/main/res/values/strings.xml

@ -39,4 +39,6 @@
<string name="fa_file_video_o">&#xf1c8;</string> <string name="fa_file_video_o">&#xf1c8;</string>
<string name="user_number_of_posts">#%1$d</string> <string name="user_number_of_posts">#%1$d</string>
<string name="byUser">by %1$s</string>
</resources> </resources>

Loading…
Cancel
Save