Browse Source

TopicActivity, CircularNetworkImageView additions and fixes. Ran inspection tool on the whole project.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
3c877c166a
  1. 6
      app/build.gradle
  2. 22
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  4. 165
      app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java
  5. 10
      app/src/main/java/gr/thmmy/mthmmy/data/Post.java
  6. 19
      app/src/main/java/gr/thmmy/mthmmy/sections/recent/RecentFragment.java
  7. 28
      app/src/main/java/gr/thmmy/mthmmy/utils/CircularNetworkImageView.java
  8. 13
      app/src/main/java/gr/thmmy/mthmmy/utils/ImageController.java
  9. 145
      app/src/main/java/gr/thmmy/mthmmy/utils/Thmmy.java
  10. 5
      app/src/main/res/drawable/box_border.xml
  11. 6
      app/src/main/res/drawable/row.xml
  12. BIN
      app/src/main/res/drawable/thmmy_3d_wshadow.png
  13. 23
      app/src/main/res/layout/activity_topic.xml
  14. 25
      app/src/main/res/layout/activity_topic_post_row.xml
  15. 3
      app/src/main/res/values/colors.xml
  16. 1
      app/src/main/res/values/dimens.xml

6
app/build.gradle

@ -9,7 +9,7 @@ android {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 25 targetSdkVersion 25
versionCode 2 versionCode 2
versionName "0.15" versionName "0.16"
} }
buildTypes { buildTypes {
release { release {
@ -21,8 +21,8 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.0' compile 'com.android.support:design:25.0.1'
compile 'com.squareup.okhttp3:okhttp:3.4.0' compile 'com.squareup.okhttp3:okhttp:3.4.0'
compile 'com.jakewharton:butterknife:7.0.1' compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.jsoup:jsoup:1.10.1' compile 'org.jsoup:jsoup:1.10.1'

22
app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java

@ -1,6 +1,5 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -14,17 +13,16 @@ import okhttp3.OkHttpClient;
public class BaseActivity extends AppCompatActivity { public class BaseActivity extends AppCompatActivity {
protected static OkHttpClient client;
protected static CookieJar cookieJar;
protected static SharedPrefsCookiePersistor sharedPrefsCookiePersistor;
protected static Thmmy.LoginData loginData;
private static boolean init =false; //To initialize stuff only once per app start
//Shared preferences //Shared preferences
public static final String SHARED_PREFS_NAME = "thmmySharedPrefs"; static final String SHARED_PREFS_NAME = "thmmySharedPrefs";
public static final String USER_NAME = "userNameKey"; static final String USER_NAME = "userNameKey";
public static final String GUEST_PREF_USERNAME = "GUEST"; static final String GUEST_PREF_USERNAME = "GUEST";
public static final String IS_LOGGED_IN = "isLogedIn"; static final String IS_LOGGED_IN = "isLoggedIn";
static OkHttpClient client;
static Thmmy.LoginData loginData;
private static CookieJar cookieJar;
private static SharedPrefsCookiePersistor sharedPrefsCookiePersistor;
private static boolean init =false; //To initialize stuff only once per app start
public static CookieJar getCookieJar() public static CookieJar getCookieJar()
{ {
@ -57,7 +55,7 @@ public class BaseActivity extends AppCompatActivity {
} }
public void setLoginData(Thmmy.LoginData loginData) { void setLoginData(Thmmy.LoginData loginData) {
BaseActivity.loginData = loginData; BaseActivity.loginData = loginData;
} }
} }

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

@ -23,8 +23,7 @@ import static gr.thmmy.mthmmy.utils.Thmmy.login;
public class LoginActivity extends BaseActivity { public class LoginActivity extends BaseActivity {
private static final String TAG = "LoginActivity"; private static final String TAG = "LoginActivity";
Button btnLogin; private Button btnLogin;
Button btnGuest;
private EditText inputUsername; private EditText inputUsername;
private EditText inputPassword; private EditText inputPassword;
private String username; private String username;
@ -38,7 +37,7 @@ public class LoginActivity extends BaseActivity {
inputUsername = (EditText) findViewById(R.id.username); inputUsername = (EditText) findViewById(R.id.username);
inputPassword = (EditText) findViewById(R.id.password); inputPassword = (EditText) findViewById(R.id.password);
btnLogin = (Button) findViewById(R.id.btnLogin); btnLogin = (Button) findViewById(R.id.btnLogin);
btnGuest = (Button) findViewById(R.id.btnContinueAsGuest); Button btnGuest = (Button) findViewById(R.id.btnContinueAsGuest);
// Login button Click Event // Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() { btnLogin.setOnClickListener(new View.OnClickListener() {
@ -83,13 +82,13 @@ public class LoginActivity extends BaseActivity {
moveTaskToBack(true); moveTaskToBack(true);
} }
public void onLoginFailed() { private void onLoginFailed() {
Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show(); Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show();
btnLogin.setEnabled(true); btnLogin.setEnabled(true);
} }
public boolean validate() { private boolean validate() {
boolean valid = true; boolean valid = true;
if (username.isEmpty()) { if (username.isEmpty()) {

165
app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java

@ -1,18 +1,16 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.EditText; import android.widget.EditText;
@ -36,20 +34,19 @@ import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.data.Post; import gr.thmmy.mthmmy.data.Post;
import gr.thmmy.mthmmy.utils.CircularNetworkImageView; import gr.thmmy.mthmmy.utils.CircularNetworkImageView;
import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.ImageController; import gr.thmmy.mthmmy.utils.ImageController;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
public class TopicActivity extends BaseActivity { public class TopicActivity extends BaseActivity {
private static final int THUMBNAIL_SIZE = 80;
private final SparseArray<String> pagesUrls = new SparseArray<>();
private ImageLoader imageLoader = ImageController.getInstance().getImageLoader(); private ImageLoader imageLoader = ImageController.getInstance().getImageLoader();
private TopicAdapter topicAdapter;
private ProgressBar progressBar; private ProgressBar progressBar;
private List<Post> postsList; private List<Post> postsList;
private EditText pageSelect; private EditText pageSelect;
private LinearLayout postsLinearLayout;
private int thisPage = 1; private int thisPage = 1;
private SparseArray<String> pagesUrls = new SparseArray<>();
private String base_url = ""; private String base_url = "";
private int numberOfPages = 1; private int numberOfPages = 1;
@ -61,6 +58,8 @@ public class TopicActivity extends BaseActivity {
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
final String topicTitle = getIntent().getExtras().getString("TOPIC_TITLE"); final String topicTitle = getIntent().getExtras().getString("TOPIC_TITLE");
postsLinearLayout = (LinearLayout) findViewById(R.id.posts_list);
progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar = (ProgressBar) findViewById(R.id.progressBar);
if (imageLoader == null) if (imageLoader == null)
@ -103,76 +102,62 @@ public class TopicActivity extends BaseActivity {
actionbar.setCustomView(customNav, lp); actionbar.setCustomView(customNav, lp);
actionbar.setDisplayShowCustomEnabled(true); actionbar.setDisplayShowCustomEnabled(true);
postsList = new ArrayList<>(); postsList = new ArrayList<>();
topicAdapter = new TopicAdapter();
CustomRecyclerView recyclerView = (CustomRecyclerView) findViewById(R.id.posts_list);
recyclerView.setLayoutManager(new LinearLayoutManager(findViewById(R.id.posts_list).getContext()));
recyclerView.setAdapter(topicAdapter);
new TopicTask().execute(extras.getString("TOPIC_URL")); new TopicTask().execute(extras.getString("TOPIC_URL"));
} }
private class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.ViewHolder> {
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { protected void onDestroy() {
View view = LayoutInflater.from(parent.getContext()) super.onDestroy();
.inflate(R.layout.activity_topic_post_row, parent, false); ImageController.getInstance().cancelPendingRequests();
return new ViewHolder(view);
} }
//---------------------------------------TOPIC ASYNC TASK-------------------------------------------
@Override private void populateLayout() {
public void onBindViewHolder(final ViewHolder holder, final int position) { LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//----------------------------------- Holder behaves erratically ----------------------------------- for (Post item : postsList) {
if (postsList.get(position).getThumbnailUrl() != "") { View convertView = inflater.inflate(R.layout.activity_topic_post_row
holder.mThumbnailView.setImageUrl(postsList.get(position).getThumbnailUrl(), imageLoader); , postsLinearLayout, false);
}
holder.mAuthorView.setText(postsList.get(position).getAuthor());
holder.mSubjectView.setText(postsList.get(position).getDateTime());
holder.mContentView.loadDataWithBaseURL("file:///android_asset/"
, postsList.get(position).getContent()
, "text/html", "UTF-8", null);
//----------------------------------- Holder behaves erratically -----------------------------------
}
@Override if (imageLoader == null)
public int getItemCount() { imageLoader = ImageController.getInstance().getImageLoader();
return postsList.size();
}
class ViewHolder extends RecyclerView.ViewHolder { CircularNetworkImageView thumbnail = (CircularNetworkImageView) convertView.findViewById(R.id.thumbnail);
final View mView; TextView username = (TextView) convertView.findViewById(R.id.username);
final CircularNetworkImageView mThumbnailView; TextView postNum = (TextView) convertView.findViewById(R.id.post_number);
final TextView mAuthorView; TextView subject = (TextView) convertView.findViewById(R.id.subject);
final TextView mSubjectView; WebView post = (WebView) convertView.findViewById(R.id.post);
final WebView mContentView;
//Avoiding errors about layout having 0 width/height
ViewHolder(View view) { thumbnail.setMinimumWidth(1);
super(view); thumbnail.setMinimumHeight(1);
mView = view; //Set thumbnail size
mThumbnailView = (CircularNetworkImageView) view.findViewById(R.id.thumbnail); thumbnail.setMaxWidth(THUMBNAIL_SIZE);
mAuthorView = (TextView) view.findViewById(R.id.username); thumbnail.setMaxHeight(THUMBNAIL_SIZE);
mSubjectView = (TextView) view.findViewById(R.id.subject);
mContentView = (WebView) view.findViewById(R.id.post); // thumbnail image
if (item.getThumbnailUrl() != null) {
thumbnail.setImageUrl(item.getThumbnailUrl(), imageLoader);
} }
username.setText(item.getAuthor());
if (item.getPostNumber() != 0)
postNum.setText("#" + item.getPostNumber());
subject.setText(item.getSubject());
post.loadDataWithBaseURL("file:///android_asset/", item.getContent(), "text/html", "UTF-8", null);
post.setEnabled(false);
postsLinearLayout.addView(convertView);
} }
} }
//---------------------------------------TOPIC ASYNC TASK-------------------------------------------
public class TopicTask extends AsyncTask<String, Void, Boolean> { public class TopicTask extends AsyncTask<String, Void, Boolean> {
private static final String TAG = "TopicTask"; private static final String TAG = "TopicTask";
private String pageLink; private String pageLink;
private Document document; private Document document;
protected void onPreExecute() { protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setVisibility(ProgressBar.VISIBLE);
} }
@ -200,10 +185,9 @@ public class TopicActivity extends BaseActivity {
} }
} }
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
topicAdapter.notifyDataSetChanged(); populateLayout();
pageSelect.setHint(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); pageSelect.setHint(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages));
} }
@ -232,37 +216,52 @@ public class TopicActivity extends BaseActivity {
} }
} }
Elements form_quickModForm = document.select("form[id=quickModForm]"); //Each element is a post row
Elements nickNames = form_quickModForm.select("a[title^=View the profile of]"); Elements rows = document.select("form[id=quickModForm]>table>tbody>tr:matches(on)");
Elements topic_subjectS = form_quickModForm.select("div[id^=subject_]");
Elements postTextS = form_quickModForm.select("div").select(".post");
Elements img_smalltexts = form_quickModForm.select("div").select(":matches(Posts:)");
//Elements replies_smalltexts = form_quickModForm.select("div.smalltext:matches(Reply #)");
for (int i = 0; i < nickNames.size(); i++) { for (Element item: rows) { //For every post
String p_userName, p_thumbnailUrl, p_subject, p_post;
int p_postNum;
String tmp_nickName = nickNames.get(i).html(); //Find the Username
Element thumbnail_urls = img_smalltexts.get(i).select("img").select(".avatar").first(); Element userName = item.select("a[title^=View the profile of]").first();
if(userName == null){ //Deleted profile
String tmp_url = ""; p_userName = item
if (thumbnail_urls != null) { .select("td:has(div.smalltext:containsOwn(Guest))[style^=overflow]")
tmp_url = thumbnail_urls.attr("abs:src"); .first().text();
p_userName = p_userName.substring(0, p_userName.indexOf(" Guest"));
}
else
p_userName = userName.html();
//Find thumbnail url
Element thumbnailUrl = item.select("img.avatar").first();
p_thumbnailUrl = null; //In case user doesn't have an avatar
if(thumbnailUrl != null){
p_thumbnailUrl = thumbnailUrl.attr("abs:src");
} }
String tmp_topic_subject = topic_subjectS.get(i).select("a").first().text();
String tmp_post_text = postTextS.get(i).html(); //Find subject
tmp_post_text = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + tmp_post_text); //style.css p_subject = item.select("div[id^=subject_]").first().select("a").first().text();
/*int tmp_postNum = 0; //topic starter //Find post's text
if (replies_smalltexts.size() == nickNames.size()) { p_post = item.select("div").select(".post").first().html();
String tmp_prep = replies_smalltexts.get(i).text().substring(9); p_post = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"
tmp_postNum = Integer.parseInt(tmp_prep.substring(0, tmp_prep.indexOf(" on"))); + p_post); //style.css
} else if (i != 0) {
String tmp_prep = replies_smalltexts.get(i - 1).text().substring(9); //Find post's index number
tmp_postNum = Integer.parseInt(tmp_prep.substring(0, tmp_prep.indexOf(" on"))); Element postNum = item.select("div.smalltext:matches(Reply #)").first();
}*/ if(postNum == null){ //Topic starter
p_postNum = 0;
}
else{
String tmp_str = postNum.text().substring(9);
p_postNum = Integer.parseInt(tmp_str.substring(0, tmp_str.indexOf(" on")));
}
postsList.add(new Post(tmp_url, tmp_nickName, tmp_topic_subject, tmp_post_text)); postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject
, p_post, p_postNum));
} }
return true; return true;
} }

10
app/src/main/java/gr/thmmy/mthmmy/data/Post.java

@ -5,13 +5,15 @@ public class Post
private final String thumbnailUrl; private final String thumbnailUrl;
private final String author; private final String author;
private final String subject; private final String subject;
private String content; private final String content;
private final int postNumber;
public Post(String thumbnailUrl, String author, String subject, String content) { public Post(String thumbnailUrl, String author, String subject, String content, int postNumber) {
this.thumbnailUrl = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
this.subject = subject; this.subject = subject;
this.content = content; this.content = content;
this.postNumber = postNumber;
} }
public String getThumbnailUrl() { return thumbnailUrl;} public String getThumbnailUrl() { return thumbnailUrl;}
@ -24,7 +26,9 @@ public class Post
return author; return author;
} }
public String getDateTime() { public String getSubject() {
return subject; return subject;
} }
public int getPostNumber(){ return postNumber;}
} }

19
app/src/main/java/gr/thmmy/mthmmy/sections/recent/RecentFragment.java

@ -50,14 +50,13 @@ public class RecentFragment extends Fragment
private ProgressBar progressBar; private ProgressBar progressBar;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
private CustomRecyclerView recyclerView;
private RecentAdapter recentAdapter; private RecentAdapter recentAdapter;
private List<TopicSummary> topicSummaries; private List<TopicSummary> topicSummaries;
private OnListFragmentInteractionListener mListener; private OnListFragmentInteractionListener mListener;
OkHttpClient client; private OkHttpClient client;
// Required empty public constructor // Required empty public constructor
public RecentFragment() {} public RecentFragment() {}
@ -154,7 +153,7 @@ public class RecentFragment extends Fragment
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
recentAdapter = new RecentAdapter(topicSummaries, mListener); recentAdapter = new RecentAdapter(topicSummaries, mListener);
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()));
recyclerView.setAdapter(recentAdapter); recyclerView.setAdapter(recentAdapter);
@ -205,11 +204,6 @@ public class RecentFragment extends Fragment
void onFragmentInteraction(TopicSummary topicSummary); void onFragmentInteraction(TopicSummary topicSummary);
} }
int n=0;
long s=0;
//---------------------------------------ASYNC TASK----------------------------------- //---------------------------------------ASYNC TASK-----------------------------------
public class RecentTask extends AsyncTask<Void, Void, Integer> public class RecentTask extends AsyncTask<Void, Void, Integer>
@ -260,7 +254,7 @@ public class RecentFragment extends Fragment
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
} }
private boolean parse(Document document) private void parse(Document document)
{ {
Elements recent = document.select("#block8 :first-child div"); Elements recent = document.select("#block8 :first-child div");
if(recent.size()==30) if(recent.size()==30)
@ -279,7 +273,7 @@ public class RecentFragment extends Fragment
else else
{ {
Log.e(TAG, "Parsing failed (lastUser)!"); Log.e(TAG, "Parsing failed (lastUser)!");
return false; return;
} }
String dateTime = recent.get(i + 2).text(); String dateTime = recent.get(i + 2).text();
@ -290,17 +284,16 @@ public class RecentFragment extends Fragment
else else
{ {
Log.e(TAG, "Parsing failed (dateTime)!"); Log.e(TAG, "Parsing failed (dateTime)!");
return false; return;
} }
topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime));
} }
return true; return;
} }
Log.e(TAG, "Parsing failed!"); Log.e(TAG, "Parsing failed!");
return false;
} }
} }

28
app/src/main/java/gr/thmmy/mthmmy/utils/CircularNetworkImageView.java

@ -15,8 +15,8 @@ import android.util.AttributeSet;
import com.android.volley.toolbox.NetworkImageView; import com.android.volley.toolbox.NetworkImageView;
public class CircularNetworkImageView extends NetworkImageView { public class CircularNetworkImageView extends NetworkImageView {
private static final int THUMBNAIL_SIZE = 100; private static final int THUMBNAIL_SIZE = 80;
Context mContext; private Context mContext;
public CircularNetworkImageView(Context context) { public CircularNetworkImageView(Context context) {
super(context); super(context);
@ -34,18 +34,6 @@ public class CircularNetworkImageView extends NetworkImageView {
mContext = context; mContext = context;
} }
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min(
maxImageSize / realImage.getWidth(),
maxImageSize / realImage.getHeight());
int width = Math.round(ratio * realImage.getWidth());
int height = Math.round(ratio * realImage.getHeight());
return Bitmap.createScaledBitmap(realImage, width,
height, filter);
}
@Override @Override
public void setImageBitmap(Bitmap bm) { public void setImageBitmap(Bitmap bm) {
if(bm==null) return; if(bm==null) return;
@ -60,18 +48,19 @@ public class CircularNetworkImageView extends NetworkImageView {
* @param bitmap * @param bitmap
* @return bitmap * @return bitmap
*/ */
public Bitmap getCircularBitmap(Bitmap bitmap) { private Bitmap getCircularBitmap(Bitmap bitmap) {
bitmap = Bitmap.createScaledBitmap(bitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888); bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output); Canvas canvas = new Canvas(output);
int width = bitmap.getWidth(); int size = bitmap.getWidth();
if(bitmap.getWidth()>bitmap.getHeight()) if(bitmap.getWidth()>bitmap.getHeight())
width = bitmap.getHeight(); size = bitmap.getHeight();
final int color = 0xff424242; final int color = 0xff424242;
final Paint paint = new Paint(); final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, width, width); final Rect rect = new Rect(0, 0, size, size);
final RectF rectF = new RectF(rect); final RectF rectF = new RectF(rect);
final float roundPx = width / 2; final float roundPx = size / 2;
paint.setAntiAlias(true); paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0); canvas.drawARGB(0, 0, 0, 0);
@ -81,7 +70,6 @@ public class CircularNetworkImageView extends NetworkImageView {
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint); canvas.drawBitmap(bitmap, rect, rect, paint);
output = scaleDown(output, THUMBNAIL_SIZE, true);
return output; return output;
} }
} }

13
app/src/main/java/gr/thmmy/mthmmy/utils/ImageController.java

@ -10,7 +10,7 @@ import com.android.volley.toolbox.Volley;
public class ImageController extends Application { public class ImageController extends Application {
public static final String TAG = ImageController.class.getSimpleName(); private static final String TAG = ImageController.class.getSimpleName();
private static ImageController mInstance; private static ImageController mInstance;
private RequestQueue mRequestQueue; private RequestQueue mRequestQueue;
private ImageLoader mImageLoader; private ImageLoader mImageLoader;
@ -25,7 +25,7 @@ public class ImageController extends Application {
mInstance = this; mInstance = this;
} }
public RequestQueue getRequestQueue() { private RequestQueue getRequestQueue() {
if (mRequestQueue == null) { if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext()); mRequestQueue = Volley.newRequestQueue(getApplicationContext());
} }
@ -53,10 +53,13 @@ public class ImageController extends Application {
getRequestQueue().add(req); getRequestQueue().add(req);
} }
public void cancelPendingRequests(Object tag) { public void cancelPendingRequests(){
if (mRequestQueue != null) { mRequestQueue.cancelAll(new RequestQueue.RequestFilter() {
mRequestQueue.cancelAll(tag); @Override
public boolean apply(Request<?> request) {
return true;
} }
});
} }
} }

145
app/src/main/java/gr/thmmy/mthmmy/utils/Thmmy.java

@ -28,9 +28,6 @@ import okhttp3.Response;
public class Thmmy { public class Thmmy {
private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2");
private static final HttpUrl indexUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php");
public static final int LOGGED_OUT = 0; public static final int LOGGED_OUT = 0;
public static final int LOGGED_IN = 1; public static final int LOGGED_IN = 1;
public static final int WRONG_USER = 2; public static final int WRONG_USER = 2;
@ -38,7 +35,7 @@ public class Thmmy {
public static final int FAILED = 4; public static final int FAILED = 4;
public static final int CERTIFICATE_ERROR = 5; public static final int CERTIFICATE_ERROR = 5;
public static final int OTHER_ERROR = 6; public static final int OTHER_ERROR = 6;
private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2");
//-------------------------------------------LOGIN-------------------------------------------------- //-------------------------------------------LOGIN--------------------------------------------------
//Two options: (username, password, duration) or nothing - cookies //Two options: (username, password, duration) or nothing - cookies
@ -116,71 +113,7 @@ public class Thmmy {
return loginData; return loginData;
} }
//To maintain data between activities/ between activity state change (possibly temporary solution) private static void setPersistentCookieSession() {
public static class LoginData implements Parcelable {
private int status;
private String username;
private HttpUrl logoutLink;
public LoginData() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public HttpUrl getLogoutLink() {
return logoutLink;
}
public void setLogoutLink(HttpUrl logoutLink) {
this.logoutLink = logoutLink;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(status);
out.writeString(username);
out.writeString(logoutLink.toString());
}
public static final Parcelable.Creator<LoginData> CREATOR
= new Parcelable.Creator<LoginData>() {
public LoginData createFromParcel(Parcel in) {
return new LoginData(in);
}
public LoginData[] newArray(int size) {
return new LoginData[size];
}
};
private LoginData(Parcel in) {
status = in.readInt();
username = in.readString();
logoutLink = HttpUrl.parse(in.readString());
}
}
private static boolean setPersistentCookieSession() {
List<Cookie> cookieList = BaseActivity.getCookieJar().loadForRequest(HttpUrl.parse("https://www.thmmy.gr")); List<Cookie> cookieList = BaseActivity.getCookieJar().loadForRequest(HttpUrl.parse("https://www.thmmy.gr"));
if (cookieList.size() == 2) { if (cookieList.size() == 2) {
@ -194,13 +127,9 @@ public class Thmmy {
cookieList.add(builder.build()); cookieList.add(builder.build());
BaseActivity.getSharedPrefsCookiePersistor().clear(); BaseActivity.getSharedPrefsCookiePersistor().clear();
BaseActivity.getSharedPrefsCookiePersistor().saveAll(cookieList); BaseActivity.getSharedPrefsCookiePersistor().saveAll(cookieList);
return true;
} }
} }
return false;
} }
//-------------------------------------LOGIN ENDS-----------------------------------------------
//--------------------------------------LOGOUT-------------------------------------------------- //--------------------------------------LOGOUT--------------------------------------------------
public static int logout(LoginData loginData) { public static int logout(LoginData loginData) {
@ -234,13 +163,10 @@ public class Thmmy {
} }
//-------------------------------------LOGIN ENDS-----------------------------------------------
//----------------------------------------LOGOUT ENDS-----------------------------------------------
//-------------------------------------------MISC--------------------------------------------------- //-------------------------------------------MISC---------------------------------------------------
public static String extractUserName(Document doc) { private static String extractUserName(Document doc) {
if (doc != null) { if (doc != null) {
Elements user = doc.select("div[id=myuser] > h3"); Elements user = doc.select("div[id=myuser] > h3");
@ -257,4 +183,67 @@ public class Thmmy {
return null; return null;
} }
//----------------------------------------LOGOUT ENDS-----------------------------------------------
//To maintain data between activities/ between activity state change (possibly temporary solution)
public static class LoginData implements Parcelable {
public static final Parcelable.Creator<LoginData> CREATOR
= new Parcelable.Creator<LoginData>() {
public LoginData createFromParcel(Parcel in) {
return new LoginData(in);
}
public LoginData[] newArray(int size) {
return new LoginData[size];
}
};
private int status;
private String username;
private HttpUrl logoutLink;
public LoginData() {
}
private LoginData(Parcel in) {
status = in.readInt();
username = in.readString();
logoutLink = HttpUrl.parse(in.readString());
}
public String getUsername() {
return username;
}
void setUsername(String username) {
this.username = username;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
HttpUrl getLogoutLink() {
return logoutLink;
}
void setLogoutLink(HttpUrl logoutLink) {
this.logoutLink = logoutLink;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(status);
out.writeString(username);
out.writeString(logoutLink.toString());
}
}
} }

5
app/src/main/res/drawable/box_border.xml

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/transparent" />
<stroke android:width="1dip" android:color="#4CFF00"/>
</shape>

6
app/src/main/res/drawable/row.xml

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="2dp" />
</shape>

BIN
app/src/main/res/drawable/thmmy_3d_wshadow.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 820 KiB

23
app/src/main/res/layout/activity_topic.xml

@ -1,26 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background" android:background="@color/background"
tools:context="gr.thmmy.mthmmy.activities.TopicActivity"> tools:context="gr.thmmy.mthmmy.activities.TopicActivity">
<ScrollView
<view
android:id="@+id/posts_list"
android:name="gr.thmmy.mthmmy.activities.Topic"
class="gr.thmmy.mthmmy.utils.CustomRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:scrollbars="none"
tools:context="gr.thmmy.mthmmy.activities.TopicActivity">
<LinearLayout
android:id="@+id/posts_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="vertical"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingTop="4dp" android:paddingTop="4dp">
app:layoutManager="LinearLayoutManager" </LinearLayout>
tools:context="gr.thmmy.mthmmy.activities.TopicActivity"
tools:listitem="@layout/activity_topic_post_row"/> </ScrollView>
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"

25
app/src/main/res/layout/activity_topic_post_row.xml

@ -37,6 +37,8 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginBottom="3dp" android:layout_marginBottom="3dp"
android:layout_marginEnd="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"> android:layout_marginTop="3dp">
<gr.thmmy.mthmmy.utils.CircularNetworkImageView <gr.thmmy.mthmmy.utils.CircularNetworkImageView
@ -44,8 +46,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="false" android:adjustViewBounds="false"
android:maxHeight="60dp" android:maxHeight="@dimen/thumbnail_size"
android:maxWidth="60dp" android:maxWidth="@dimen/thumbnail_size"
android:paddingEnd="2dp" android:paddingEnd="2dp"
android:paddingLeft="2dp" android:paddingLeft="2dp"
android:paddingRight="5dp" android:paddingRight="5dp"
@ -57,11 +59,27 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_toEndOf="@+id/thumbnail_holder" android:layout_toEndOf="@+id/thumbnail_holder"
android:layout_toRightOf="@+id/thumbnail_holder" android:layout_toRightOf="@+id/thumbnail_holder"
android:ellipsize="end"
android:maxLines="1"
android:text="sometext" android:text="sometext"
android:textColor="@color/black"
android:textStyle="bold"/> android:textStyle="bold"/>
<TextView
android:id="@+id/post_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="100dp"
android:layout_marginStart="100dp"
android:text=""/>
<TextView <TextView
android:id="@+id/subject" android:id="@+id/subject"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -69,7 +87,8 @@
android:layout_below="@+id/username" android:layout_below="@+id/username"
android:layout_toEndOf="@+id/thumbnail_holder" android:layout_toEndOf="@+id/thumbnail_holder"
android:layout_toRightOf="@+id/thumbnail_holder" android:layout_toRightOf="@+id/thumbnail_holder"
android:text="sometext"/> android:text="sometext"
/>
</RelativeLayout> </RelativeLayout>

3
app/src/main/res/values/colors.xml

@ -11,7 +11,8 @@
<color name="divider">#8B8B8B</color> <color name="divider">#8B8B8B</color>
<color name="transparent">#00000000</color> <color name="transparent">#00000000</color>
<color name="white">#ffffff</color> <color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="iron">#CCCCCC</color> <color name="iron">#CCCCCC</color>
<color name="background">#D3D3D3</color> <color name="background">#D3D3D3</color>
</resources> </resources>

1
app/src/main/res/values/dimens.xml

@ -4,4 +4,5 @@
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen> <dimen name="appbar_padding_top">8dp</dimen>
<dimen name="thumbnail_size">80dp</dimen>
</resources> </resources>

Loading…
Cancel
Save