Browse Source

Code cleanup

pull/24/head
Ezerous 8 years ago
parent
commit
7a28f9b8d7
  1. 2
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  3. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  4. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseActivity.java
  5. 86
      app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseFragment.java
  6. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  7. 29
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java
  8. 114
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  9. 28
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java
  10. 104
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  11. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  12. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java
  13. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

2
app/src/main/AndroidManifest.xml

@ -49,7 +49,7 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity"/> android:value=".activities.main.MainActivity"/>
</activity> </activity>
<activity android:name=".activities.BaseActivity"/> <activity android:name=".activities.base.BaseActivity"/>
<activity <activity
android:name=".activities.profile.ProfileActivity" android:name=".activities.profile.ProfileActivity"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">

2
app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

@ -1,7 +1,6 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.AppBarLayout; import android.support.design.widget.AppBarLayout;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
@ -15,6 +14,7 @@ import android.widget.Toast;
import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.BuildConfig;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.base.BaseActivity;
public class AboutActivity extends BaseActivity { public class AboutActivity extends BaseActivity {
private static final int TIME_INTERVAL = 1000; private static final int TIME_INTERVAL = 1000;

1
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -12,6 +12,7 @@ import android.widget.ScrollView;
import android.widget.Toast; import android.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import mthmmy.utils.Report; import mthmmy.utils.Report;

6
app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java → app/src/main/java/gr/thmmy/mthmmy/activities/base/BaseActivity.java

@ -1,4 +1,4 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities.base;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@ -37,13 +37,15 @@ import com.squareup.picasso.Picasso;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.AboutActivity;
import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN; import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
public class BaseActivity extends AppCompatActivity public abstract class BaseActivity extends AppCompatActivity
{ {
// Client & Cookies // Client & Cookies
protected static OkHttpClient client; protected static OkHttpClient client;

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

@ -0,0 +1,86 @@
package gr.thmmy.mthmmy.activities.base;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import mthmmy.utils.Report;
import okhttp3.OkHttpClient;
public abstract class BaseFragment extends Fragment {
protected static final String ARG_SECTION_NUMBER = "SectionNumber";
protected static final String ARG_TAG = "FragmentTAG";
protected FragmentInteractionListener fragmentInteractionListener;
private String TAG;
protected int sectionNumber;
protected OkHttpClient client;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TAG = getArguments().getString(ARG_TAG);
sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
client = BaseActivity.getClient();
Report.d(TAG, "onCreate");
}
@Override
public void onStart() {
super.onStart();
Report.d(TAG, "onStart");
}
@Override
public void onResume() {
super.onResume();
Report.d(TAG, "onResume");
}
@Override
public void onPause() {
super.onPause();
Report.d(TAG, "onPause");
}
@Override
public void onStop() {
super.onStop();
Report.d(TAG, "onStop");
}
@Override
public void onDestroy() {
super.onDestroy();
cancelTask();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof FragmentInteractionListener) {
fragmentInteractionListener = (FragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
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,
* between the fragment and the activity/ other fragments
*/
public interface FragmentInteractionListener {}
}

4
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -11,8 +11,8 @@ import android.support.v7.widget.Toolbar;
import android.widget.Toast; import android.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment;
import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.main.recent.RecentFragment;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
@ -20,7 +20,7 @@ import gr.thmmy.mthmmy.data.TopicSummary;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT; import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT;
public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener, ForumFragment.OnListFragmentInteractionListener { public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener {
//----------------------------------------CLASS VARIABLES----------------------------------------- //----------------------------------------CLASS VARIABLES-----------------------------------------
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";

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

@ -9,21 +9,21 @@ import android.widget.TextView;
import java.util.List; import java.util.List;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
/** /**
* {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the
* specified {@link RecentFragment.OnListFragmentInteractionListener}. * specified {@link ForumFragment.ForumFragmentInteractionListener}.
*/ */
public class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> { class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder> {
private final List<TopicSummary> recentList; private final List<TopicSummary> recentList;
private final ForumFragment.OnListFragmentInteractionListener mListener; private final ForumFragment.ForumFragmentInteractionListener mListener;
public ForumAdapter(List<TopicSummary> topicSummaryList, ForumFragment.OnListFragmentInteractionListener listener) { ForumAdapter(List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) {
this.recentList = topicSummaryList; this.recentList = topicSummaryList;
mListener = listener; mListener = (ForumFragment.ForumFragmentInteractionListener)listener;
} }
@ -64,24 +64,19 @@ public class ForumAdapter extends RecyclerView.Adapter<ForumAdapter.ViewHolder>
return recentList.size(); return recentList.size();
} }
public class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
public final View mView; final View mView;
public final TextView mTitleView; final TextView mTitleView;
public final TextView mUserView; final TextView mUserView;
public final TextView mDateTimeView; final TextView mDateTimeView;
public TopicSummary topic; public TopicSummary topic;
public ViewHolder(View view) { ViewHolder(View view) {
super(view); super(view);
mView = view; mView = view;
mTitleView = (TextView) view.findViewById(R.id.title); mTitleView = (TextView) view.findViewById(R.id.title);
mUserView = (TextView) view.findViewById(R.id.lastUser); mUserView = (TextView) view.findViewById(R.id.lastUser);
mDateTimeView = (TextView) view.findViewById(R.id.dateTime); mDateTimeView = (TextView) view.findViewById(R.id.dateTime);
} }
// @Override
// public String toString() {
// return super.toString() + " '" + mContentView.getText() + "'";
// }
} }
} }

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

@ -1,9 +1,7 @@
package gr.thmmy.mthmmy.activities.main.forum; package gr.thmmy.mthmmy.activities.main.forum;
import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -24,30 +22,27 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
/** /**
* A simple {@link Fragment} subclass. * A {@link BaseFragment} subclass.
* Activities that contain this fragment must implement the * Activities that contain this fragment must implement the
* {@link ForumFragment.OnListFragmentInteractionListener} interface * {@link ForumFragment.ForumFragmentInteractionListener} interface
* to handle interaction events. * to handle interaction events.
* Use the {@link ForumFragment#newInstance} factory method to * Use the {@link ForumFragment#newInstance} factory method to
* create an instance of this fragment. * create an instance of this fragment.
*/ */
public class ForumFragment extends Fragment public class ForumFragment extends BaseFragment
{ {
private static final String TAG = "ForumFragment"; private static final String TAG = "ForumFragment";
// Fragment initialization parameters, e.g. ARG_SECTION_NUMBER // Fragment initialization parameters, e.g. ARG_SECTION_NUMBER
private static final String ARG_SECTION_NUMBER = "SectionNumber";
private int sectionNumber;
private ProgressBar progressBar; private ProgressBar progressBar;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
@ -55,13 +50,10 @@ public class ForumFragment extends Fragment
private List<TopicSummary> topicSummaries; private List<TopicSummary> topicSummaries;
private OnListFragmentInteractionListener mListener; private ForumTask forumTask;
private OkHttpClient client;
// Required empty public constructor // Required empty public constructor
public ForumFragment() { public ForumFragment() {}
}
/** /**
* Use ONLY this factory method to create a new instance of * Use ONLY this factory method to create a new instance of
@ -73,28 +65,16 @@ public class ForumFragment extends Fragment
public static ForumFragment newInstance(int sectionNumber) { public static ForumFragment newInstance(int sectionNumber) {
ForumFragment fragment = new ForumFragment(); ForumFragment fragment = new ForumFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_TAG, TAG);
args.putInt(ARG_SECTION_NUMBER, sectionNumber); args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
public int getSectionNumber() {
return sectionNumber;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
client = BaseActivity.getClient();
topicSummaries = new ArrayList<>(); topicSummaries = new ArrayList<>();
if (sectionNumber == 1) //?
Report.d(TAG, "onCreate");
} }
@Override @Override
@ -102,43 +82,11 @@ public class ForumFragment extends Fragment
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (sectionNumber == 1)//temp if (sectionNumber == 1)//temp
{ {
if (topicSummaries.isEmpty()) if (topicSummaries.isEmpty()) new ForumTask().execute();
new RecentTask().execute();
} }
Report.d(TAG, "onActivityCreated"); Report.d(TAG, "onActivityCreated");
} }
@Override
public void onStart() {
super.onStart();
if (sectionNumber == 1)
Report.d(TAG, "onStart");
}
@Override
public void onResume() {
super.onResume();
if (sectionNumber == 1)
Report.d(TAG, "onResume");
}
@Override
public void onPause() {
super.onPause();
if (sectionNumber == 1)
Report.d(TAG, "onPause");
}
@Override
public void onStop() {
super.onStop();
if (sectionNumber == 1)
Report.d(TAG, "onStop");
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -148,7 +96,7 @@ public class ForumFragment extends Fragment
// 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, mListener); forumAdapter = new ForumAdapter(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()));
@ -159,52 +107,32 @@ public class ForumFragment extends Fragment
new SwipeRefreshLayout.OnRefreshListener() { new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
new RecentTask().execute(); if (forumTask != null && forumTask.getStatus() != AsyncTask.Status.RUNNING) {
forumTask = new ForumTask();
forumTask.execute();
}
} }
} }
); );
} }
return rootView; return rootView;
} }
@Override @Override
public void onAttach(Context context) { protected void cancelTask() {
super.onAttach(context); if(forumTask!=null&&forumTask.getStatus()!= AsyncTask.Status.RUNNING)
if (context instanceof OnListFragmentInteractionListener) { forumTask.cancel(true);
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
} }
/** public interface ForumFragmentInteractionListener extends FragmentInteractionListener{
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
*/
public interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(TopicSummary topicSummary); void onFragmentInteraction(TopicSummary topicSummary);
} }
//---------------------------------------ASYNC TASK----------------------------------- //---------------------------------------ASYNC TASK-----------------------------------
public class RecentTask extends AsyncTask<Void, Void, Integer> { public class ForumTask extends AsyncTask<Void, Void, Integer> {
private static final String TAG = "RecentTask"; private static final String TAG = "ForumTask";
private final HttpUrl thmmyUrl = SessionManager.indexUrl; private final HttpUrl thmmyUrl = SessionManager.indexUrl;
private Document document; private Document document;
@ -226,10 +154,10 @@ public class ForumFragment extends Fragment
parse(document); parse(document);
return 0; return 0;
} catch (IOException e) { } catch (IOException e) {
Report.d("DEB", "ERROR", e); Report.d(TAG, "Network Error", e);
return 1; return 1;
} catch (Exception e) { } catch (Exception e) {
Report.d("DEB", "ERROR", e); Report.d(TAG, "ERROR", e);
return 2; return 2;
} }

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

@ -9,20 +9,21 @@ import android.widget.TextView;
import java.util.List; import java.util.List;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
/** /**
* {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the
* specified {@link RecentFragment.OnListFragmentInteractionListener}. * specified {@link RecentFragment.RecentFragmentInteractionListener}.
*/ */
public class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> { class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder> {
private final List<TopicSummary> recentList; private final List<TopicSummary> recentList;
private final RecentFragment.OnListFragmentInteractionListener mListener; private final RecentFragment.RecentFragmentInteractionListener mListener;
public RecentAdapter(List<TopicSummary> topicSummaryList, RecentFragment.OnListFragmentInteractionListener listener) { RecentAdapter(List<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) {
this.recentList = topicSummaryList; this.recentList = topicSummaryList;
mListener = listener; mListener = (RecentFragment.RecentFragmentInteractionListener) listener;
} }
@ -63,24 +64,19 @@ public class RecentAdapter extends RecyclerView.Adapter<RecentAdapter.ViewHolder
return recentList.size(); return recentList.size();
} }
public class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
public final View mView; final View mView;
public final TextView mTitleView; final TextView mTitleView;
public final TextView mUserView; final TextView mUserView;
public final TextView mDateTimeView; final TextView mDateTimeView;
public TopicSummary topic; public TopicSummary topic;
public ViewHolder(View view) { ViewHolder(View view) {
super(view); super(view);
mView = view; mView = view;
mTitleView = (TextView) view.findViewById(R.id.title); mTitleView = (TextView) view.findViewById(R.id.title);
mUserView = (TextView) view.findViewById(R.id.lastUser); mUserView = (TextView) view.findViewById(R.id.lastUser);
mDateTimeView = (TextView) view.findViewById(R.id.dateTime); mDateTimeView = (TextView) view.findViewById(R.id.dateTime);
} }
// @Override
// public String toString() {
// return super.toString() + " '" + mContentView.getText() + "'";
// }
} }
} }

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

@ -1,9 +1,7 @@
package gr.thmmy.mthmmy.activities.main.recent; package gr.thmmy.mthmmy.activities.main.recent;
import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -24,29 +22,26 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
/** /**
* A simple {@link Fragment} subclass. * A {@link BaseFragment} subclass.
* Activities that contain this fragment must implement the * Activities that contain this fragment must implement the
* {@link RecentFragment.OnListFragmentInteractionListener} interface * {@link RecentFragment.RecentFragmentInteractionListener} interface
* to handle interaction events. * to handle interaction events.
* Use the {@link RecentFragment#newInstance} factory method to * Use the {@link RecentFragment#newInstance} factory method to
* create an instance of this fragment. * create an instance of this fragment.
*/ */
public class RecentFragment extends Fragment { public class RecentFragment extends BaseFragment {
private static final String TAG = "RecentFragment"; private static final String TAG = "RecentFragment";
// Fragment initialization parameters, e.g. ARG_SECTION_NUMBER // Fragment initialization parameters, e.g. ARG_SECTION_NUMBER
private static final String ARG_SECTION_NUMBER = "SectionNumber";
private int sectionNumber;
private ProgressBar progressBar; private ProgressBar progressBar;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
@ -54,15 +49,10 @@ public class RecentFragment extends Fragment {
private List<TopicSummary> topicSummaries; private List<TopicSummary> topicSummaries;
private OnListFragmentInteractionListener mListener;
private OkHttpClient client;
private RecentTask recentTask; private RecentTask recentTask;
// Required empty public constructor // Required empty public constructor
public RecentFragment() { public RecentFragment() {}
}
/** /**
* Use ONLY this factory method to create a new instance of * Use ONLY this factory method to create a new instance of
@ -74,28 +64,16 @@ public class RecentFragment extends Fragment {
public static RecentFragment newInstance(int sectionNumber) { public static RecentFragment newInstance(int sectionNumber) {
RecentFragment fragment = new RecentFragment(); RecentFragment fragment = new RecentFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_TAG, TAG);
args.putInt(ARG_SECTION_NUMBER, sectionNumber); args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
public int getSectionNumber() {
return sectionNumber;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
client = BaseActivity.getClient();
topicSummaries = new ArrayList<>(); topicSummaries = new ArrayList<>();
if (sectionNumber == 1) //?
Report.d(TAG, "onCreate");
} }
@Override @Override
@ -113,34 +91,6 @@ public class RecentFragment extends Fragment {
Report.d(TAG, "onActivityCreated"); Report.d(TAG, "onActivityCreated");
} }
@Override
public void onStart() {
super.onStart();
if (sectionNumber == 1)
Report.d(TAG, "onStart");
}
@Override
public void onResume() {
super.onResume();
if (sectionNumber == 1)
Report.d(TAG, "onResume");
}
@Override
public void onPause() {
super.onPause();
if (sectionNumber == 1)
Report.d(TAG, "onPause");
}
@Override
public void onStop() {
super.onStop();
if (sectionNumber == 1)
Report.d(TAG, "onStop");
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -151,7 +101,7 @@ public class RecentFragment extends Fragment {
// 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, mListener); recentAdapter = new RecentAdapter(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()));
@ -162,63 +112,33 @@ public class RecentFragment extends Fragment {
new SwipeRefreshLayout.OnRefreshListener() { new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
if(recentTask!=null&&recentTask.getStatus()!= AsyncTask.Status.RUNNING) { if (recentTask != null && recentTask.getStatus() != AsyncTask.Status.RUNNING) {
recentTask = new RecentTask(); recentTask = new RecentTask();
recentTask.execute(); recentTask.execute();
} }
} }
} }
); );
} }
return rootView; return rootView;
} }
@Override @Override
public void onAttach(Context context) { protected void cancelTask() {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
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 {
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
*/
public interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(TopicSummary topicSummary); void onFragmentInteraction(TopicSummary topicSummary);
} }
//---------------------------------------ASYNC TASK----------------------------------- //---------------------------------------ASYNC TASK-----------------------------------
public class RecentTask extends AsyncTask<Void, Void, Integer> { public class RecentTask extends AsyncTask<Void, Void, Integer> {
private static final String TAG = "RecentTask"; private static final String TAG = "ForumTask";
private final HttpUrl thmmyUrl = SessionManager.indexUrl; private final HttpUrl thmmyUrl = SessionManager.indexUrl;
private Document document; private Document document;
@ -239,7 +159,7 @@ public class RecentFragment extends Fragment {
parse(document); parse(document);
return 0; return 0;
} catch (IOException e) { } catch (IOException e) {
Report.d(TAG, "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, "ERROR", e);

3
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -10,7 +10,6 @@ import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -28,8 +27,8 @@ import java.util.ArrayList;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.CircleTransform;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.Request; import okhttp3.Request;

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java

@ -1,7 +1,5 @@
package gr.thmmy.mthmmy.activities.profile; package gr.thmmy.mthmmy.activities.profile;
import android.util.Log;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;

5
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -31,16 +31,13 @@ import org.jsoup.nodes.Document;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.data.Post; import gr.thmmy.mthmmy.data.Post;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.Call; import okhttp3.Call;

Loading…
Cancel
Save