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. 19
      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");
}
@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,

7
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<ForumAdapter.ViewHolder> {
private final Context context;
private final List<TopicSummary> recentList;
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;
mListener = (ForumFragment.ForumFragmentInteractionListener)listener;
}
@ -40,7 +43,7 @@ class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> {
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);

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
* 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;
}

7
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<RecentAdapter.ViewHolder> {
private final Context context;
private final List<TopicSummary> recentList;
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;
mListener = (RecentFragment.RecentFragmentInteractionListener) listener;
}
@ -40,7 +43,7 @@ class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> {
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);

19
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;
}

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

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

Loading…
Cancel
Save