From ad06299dc311742afc1229ee9b93bafc58375911 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 24 Dec 2016 16:19:28 +0200 Subject: [PATCH] More tiny cleanups --- .../mthmmy/activities/base/BaseFragment.java | 8 -------- .../activities/main/forum/ForumAdapter.java | 7 +++++-- .../activities/main/forum/ForumFragment.java | 15 ++++++++------- .../activities/main/recent/RecentAdapter.java | 7 +++++-- .../main/recent/RecentFragment.java | 19 ++++++++----------- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java index efa61dba..6b0b93c9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java +++ b/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"); } - @Override - public void onDestroy() { - super.onDestroy(); - cancelTask(); - } - @Override public void onAttach(Context context) { super.onAttach(context); @@ -75,8 +69,6 @@ public abstract class BaseFragment extends Fragment { fragmentInteractionListener = null; } - protected abstract void cancelTask(); - /** * This interface MUST be extended by the fragment subclass AND implemented by * the activity that contains it, to allow communication upon interaction, diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java index 9fe11cf1..ac2e95e9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.main.forum; +import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -18,10 +19,12 @@ import gr.thmmy.mthmmy.data.TopicSummary; * specified {@link ForumFragment.ForumFragmentInteractionListener}. */ class ForumAdapter extends RecyclerView.Adapter { + private final Context context; private final List recentList; private final ForumFragment.ForumFragmentInteractionListener mListener; - ForumAdapter(List topicSummaryList, BaseFragment.FragmentInteractionListener listener) { + ForumAdapter(Context context, List topicSummaryList, BaseFragment.FragmentInteractionListener listener) { + this.context = context; this.recentList = topicSummaryList; mListener = (ForumFragment.ForumFragmentInteractionListener)listener; } @@ -40,7 +43,7 @@ class ForumAdapter extends RecyclerView.Adapter { holder.mTitleView.setText(recentList.get(position).getTitle()); 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); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index f4f48bc6..85244dbc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/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 * this fragment using the provided parameters. - * - * @param sectionNumber * @return A new instance of fragment Forum. */ public static ForumFragment newInstance(int sectionNumber) { @@ -80,9 +78,11 @@ public class ForumFragment extends BaseFragment @Override public void onActivityCreated(Bundle 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"); } @@ -96,7 +96,7 @@ public class ForumFragment extends BaseFragment // Set the adapter if (rootView instanceof RelativeLayout) { 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); recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext())); @@ -120,7 +120,8 @@ public class ForumFragment extends BaseFragment } @Override - protected void cancelTask() { + public void onDestroy() { + super.onDestroy(); if(forumTask!=null&&forumTask.getStatus()!= AsyncTask.Status.RUNNING) forumTask.cancel(true); } @@ -157,7 +158,7 @@ public class ForumFragment extends BaseFragment Report.d(TAG, "Network Error", e); return 1; } catch (Exception e) { - Report.d(TAG, "ERROR", e); + Report.d(TAG, "Exception", e); return 2; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index f5460ccb..a81b0cdd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.main.recent; +import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -18,10 +19,12 @@ import gr.thmmy.mthmmy.data.TopicSummary; * specified {@link RecentFragment.RecentFragmentInteractionListener}. */ class RecentAdapter extends RecyclerView.Adapter { + private final Context context; private final List recentList; private final RecentFragment.RecentFragmentInteractionListener mListener; - RecentAdapter(List topicSummaryList, BaseFragment.FragmentInteractionListener listener) { + RecentAdapter(Context context, List topicSummaryList, BaseFragment.FragmentInteractionListener listener) { + this.context = context; this.recentList = topicSummaryList; mListener = (RecentFragment.RecentFragmentInteractionListener) listener; } @@ -40,7 +43,7 @@ class RecentAdapter extends RecyclerView.Adapter { holder.mTitleView.setText(recentList.get(position).getTitle()); 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); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index cf29ed2d..dac762de 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/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 * this fragment using the provided parameters. - * - * @param sectionNumber * @return A new instance of fragment Recent. */ public static RecentFragment newInstance(int sectionNumber) { @@ -79,14 +77,11 @@ public class RecentFragment extends BaseFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (sectionNumber == 1)//temp + if (topicSummaries.isEmpty()) { - if (topicSummaries.isEmpty()) - { - recentTask =new RecentTask(); - recentTask.execute(); + recentTask =new RecentTask(); + recentTask.execute(); - } } Report.d(TAG, "onActivityCreated"); } @@ -101,7 +96,7 @@ public class RecentFragment extends BaseFragment { // Set the adapter if (rootView instanceof RelativeLayout) { 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); recyclerView.setLayoutManager(new LinearLayoutManager(rootView.findViewById(R.id.list).getContext())); @@ -126,11 +121,13 @@ public class RecentFragment extends BaseFragment { } @Override - protected void cancelTask() { + public void onDestroy() { + super.onDestroy(); if(recentTask!=null&&recentTask.getStatus()!= AsyncTask.Status.RUNNING) recentTask.cancel(true); } + public interface RecentFragmentInteractionListener extends FragmentInteractionListener { void onFragmentInteraction(TopicSummary topicSummary); } @@ -162,7 +159,7 @@ public class RecentFragment extends BaseFragment { Report.d(TAG, "Network Error", e); return 1; } catch (Exception e) { - Report.d(TAG, "ERROR", e); + Report.d(TAG, "Exception", e); return 2; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6e0de1f..d8f09886 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,4 +39,6 @@ #%1$d + + by %1$s