Browse Source

Work on reply FAB and quote button

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
35c9c747d3
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  2. 114
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 6
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  4. BIN
      app/src/main/res/drawable/ic_format_quote_accent.png
  5. BIN
      app/src/main/res/drawable/ic_format_quote_grey.png
  6. 5
      app/src/main/res/drawable/ic_toggle_quote_bg.xml
  7. 11
      app/src/main/res/layout/activity_topic_post_row.xml
  8. 20
      app/src/main/res/values/colors.xml

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

@ -35,7 +35,7 @@ public class BaseActivity extends AppCompatActivity
private static SharedPrefsCookiePersistor sharedPrefsCookiePersistor; private static SharedPrefsCookiePersistor sharedPrefsCookiePersistor;
//Shared Preferences //Shared Preferences
private static final String SHARED_PREFS_NAME = "ThmmySharedPrefs"; protected static final String SHARED_PREFS_NAME = "ThmmySharedPrefs";
protected static SharedPreferences sharedPrefs; protected static SharedPreferences sharedPrefs;
//SessionManager //SessionManager

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

@ -4,13 +4,17 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
@ -52,6 +56,9 @@ import gr.thmmy.mthmmy.utils.ImageController;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
import static gr.thmmy.mthmmy.session.SessionManager.LOGIN_STATUS;
public class TopicActivity extends BaseActivity { public class TopicActivity extends BaseActivity {
//-----------------------------------------CLASS VARIABLES------------------------------------------ //-----------------------------------------CLASS VARIABLES------------------------------------------
@ -61,10 +68,8 @@ public class TopicActivity extends BaseActivity {
private LinearLayout postsLinearLayout; private LinearLayout postsLinearLayout;
private static final int NO_POST_FOCUS = -1; private static final int NO_POST_FOCUS = -1;
private int postFocus = NO_POST_FOCUS; private int postFocus = NO_POST_FOCUS;
//Quote //Quote
//TODO private final ArrayList<Integer> toQuoteList = new ArrayList<>();
/* --Topic's pages-- */ /* --Topic's pages-- */
private int thisPage = 1; private int thisPage = 1;
private String base_url = ""; private String base_url = "";
@ -93,6 +98,7 @@ public class TopicActivity extends BaseActivity {
private static final String TAG = "TopicActivity"; private static final String TAG = "TopicActivity";
private String topicTitle; private String topicTitle;
private String parsedTitle; private String parsedTitle;
private FloatingActionButton replyFAB;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -137,6 +143,42 @@ public class TopicActivity extends BaseActivity {
nextPage.setEnabled(false); nextPage.setEnabled(false);
lastPage.setEnabled(false); lastPage.setEnabled(false);
replyFAB = (FloatingActionButton) findViewById(R.id.fab);
replyFAB.setEnabled(false);
replyFAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
int tmp_curr_status = sharedPrefs.getInt(LOGIN_STATUS, -1);
if(tmp_curr_status == -1){
new AlertDialog.Builder(TopicActivity.this)
.setTitle("ERROR!")
.setMessage("An error occurred while trying to find your LOGIN_STATUS.\n" +
"Please sent below info to developers:\n"
+ getLocalClassName() + "." + "l"
+ Thread.currentThread().getStackTrace()[1].getLineNumber())
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
else if(tmp_curr_status != LOGGED_IN){
new AlertDialog.Builder(TopicActivity.this, R.style.AppTheme_Dark_Dialog)
.setTitle(" ")
.setMessage("You need to be logged in to reply!")
.setIcon(android.R.drawable.ic_secure)
.show();
}
else{
//TODO
//Reply
}
}
});
new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing
} }
@ -484,14 +526,14 @@ public class TopicActivity extends BaseActivity {
} }
//Add new post in postsList, extended information needed //Add new post in postsList, extended information needed
postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post
, p_postIndex, p_postNum, p_postDate, p_isDeleted, p_rank , p_postIndex, p_postNum, p_postDate, false, p_rank
, p_specialRank, p_gender, p_numberOfPosts, p_personalText , p_specialRank, p_gender, p_numberOfPosts, p_personalText
, p_urlOfStars, p_numberOfStars)); , p_urlOfStars, p_numberOfStars));
} else{ //Deleted user } else{ //Deleted user
//Add new post in postsList, only standard information needed //Add new post in postsList, only standard information needed
postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject
, p_post, p_postIndex, p_postNum, p_postDate, p_isDeleted)); , p_post, p_postIndex, p_postNum, p_postDate, true));
} }
} }
} }
@ -506,6 +548,9 @@ public class TopicActivity extends BaseActivity {
* adds a card for each post to the ScrollView. * adds a card for each post to the ScrollView.
*/ */
private void populateLayout() { private void populateLayout() {
//Enable reply button
replyFAB.setEnabled(true);
//Set topic title if not already present //Set topic title if not already present
if (topicTitle == null || Objects.equals(topicTitle, "")) { if (topicTitle == null || Objects.equals(topicTitle, "")) {
topicTitle = parsedTitle; topicTitle = parsedTitle;
@ -525,7 +570,7 @@ public class TopicActivity extends BaseActivity {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Create a card for each post //Create a card for each post
for (Post item : postsList) { for (final Post currentPost : postsList) {
//Inflate a topic post row layout //Inflate a topic post row layout
View convertView = inflater.inflate(R.layout.activity_topic_post_row View convertView = inflater.inflate(R.layout.activity_topic_post_row
, postsLinearLayout, false); , postsLinearLayout, false);
@ -544,6 +589,8 @@ public class TopicActivity extends BaseActivity {
final TextView username = (TextView) convertView.findViewById(R.id.username); final TextView username = (TextView) convertView.findViewById(R.id.username);
final TextView subject = (TextView) convertView.findViewById(R.id.subject); final TextView subject = (TextView) convertView.findViewById(R.id.subject);
final WebView post = (WebView) convertView.findViewById(R.id.post); final WebView post = (WebView) convertView.findViewById(R.id.post);
final ImageButton quoteToggle = (ImageButton) convertView.findViewById(R.id.toggle_quote_button);
//User's extra //User's extra
RelativeLayout header = (RelativeLayout) convertView.findViewById(R.id.header); RelativeLayout header = (RelativeLayout) convertView.findViewById(R.id.header);
final LinearLayout userExtraInfo = (LinearLayout) convertView.findViewById(R.id.user_extra_info); final LinearLayout userExtraInfo = (LinearLayout) convertView.findViewById(R.id.user_extra_info);
@ -560,42 +607,61 @@ public class TopicActivity extends BaseActivity {
thumbnail.setMaxHeight(THUMBNAIL_SIZE); thumbnail.setMaxHeight(THUMBNAIL_SIZE);
//Thumbnail image set //Thumbnail image set
if (item.getThumbnailUrl() != null) { if (currentPost.getThumbnailUrl() != null) {
thumbnail.setImageUrl(item.getThumbnailUrl(), imageLoader); thumbnail.setImageUrl(currentPost.getThumbnailUrl(), imageLoader);
} }
//Username set //Username set
username.setText(item.getAuthor()); username.setText(currentPost.getAuthor());
//Post's submit date set //Post's submit date set
postDate.setText(item.getPostDate()); postDate.setText(currentPost.getPostDate());
//Post's index number set //Post's index number set
if (item.getPostNumber() != 0) if (currentPost.getPostNumber() != 0)
postNum.setText("#" + item.getPostNumber()); postNum.setText("#" + currentPost.getPostNumber());
else else
postNum.setText(""); postNum.setText("");
//Post's subject set //Post's subject set
subject.setText(item.getSubject()); subject.setText(currentPost.getSubject());
//Post's text set //Post's text set
post.loadDataWithBaseURL("file:///android_asset/", item.getContent(), "text/html", "UTF-8", null); post.loadDataWithBaseURL("file:///android_asset/", currentPost.getContent(), "text/html", "UTF-8", null);
quoteToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(view.isSelected()){
if(toQuoteList.contains(currentPost.getPostNumber())) {
toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber()));
view.setSelected(false);
}
else
Log.i(TAG, "An error occurred while trying to exclude post from" +
"toQuoteList, post wasn't there!");
}
else{
toQuoteList.add(currentPost.getPostNumber());
view.setSelected(true);
}
}
});
//If user is not deleted then we have more to do //If user is not deleted then we have more to do
if(!item.isDeleted()) { //Set extra info if(!currentPost.isDeleted()) { //Set extra info
//Variables for Graphics //Variables for Graphics
TextView g_specialRank, g_rank, g_gender, g_numberOfPosts, g_personalText; TextView g_specialRank, g_rank, g_gender, g_numberOfPosts, g_personalText;
LinearLayout g_stars_holder = (LinearLayout) convertView.findViewById(R.id.stars); LinearLayout g_stars_holder = (LinearLayout) convertView.findViewById(R.id.stars);
//Variables for content //Variables for content
String c_specialRank = item.getSpecialRank() String c_specialRank = currentPost.getSpecialRank()
, c_rank = item.getRank() , c_rank = currentPost.getRank()
, c_gender = item.getGender() , c_gender = currentPost.getGender()
, c_numberOfPosts = item.getNumberOfPosts() , c_numberOfPosts = currentPost.getNumberOfPosts()
, c_personalText = item.getPersonalText() , c_personalText = currentPost.getPersonalText()
, c_urlOfStars = item.getUrlOfStars(); , c_urlOfStars = currentPost.getUrlOfStars();
int c_numberOfStars = item.getNumberOfStars(); int c_numberOfStars = currentPost.getNumberOfStars();
if(!Objects.equals(c_specialRank, "") && c_specialRank != null){ if(!Objects.equals(c_specialRank, "") && c_specialRank != null){
g_specialRank = (TextView) convertView.findViewById(R.id.special_rank); g_specialRank = (TextView) convertView.findViewById(R.id.special_rank);
@ -684,7 +750,7 @@ public class TopicActivity extends BaseActivity {
final Runnable WebViewLongClick = new Runnable() { final Runnable WebViewLongClick = new Runnable() {
public void run() { public void run() {
wasLongClick = true; wasLongClick = true;
//TODO quoteToggle.performClick();
} }
}; };
@ -755,7 +821,7 @@ public class TopicActivity extends BaseActivity {
//Set post focus //Set post focus
if(postFocus != NO_POST_FOCUS){ if(postFocus != NO_POST_FOCUS){
if(item.getPostIndex() == postFocus){ if(currentPost.getPostIndex() == postFocus){
//TODO //TODO
} }
} }

6
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -58,9 +58,9 @@ public class SessionManager
//Shared Preferences & its keys //Shared Preferences & its keys
private SharedPreferences sharedPrefs; private SharedPreferences sharedPrefs;
private static final String USERNAME = "Username"; public static final String USERNAME = "Username";
private static final String LOGOUT_LINK = "LogoutLink"; public static final String LOGOUT_LINK = "LogoutLink";
private static final String LOGIN_STATUS = "IsLoggedIn"; public static final String LOGIN_STATUS = "IsLoggedIn";
//Constructor //Constructor
public SessionManager(OkHttpClient client, PersistentCookieJar cookieJar, public SessionManager(OkHttpClient client, PersistentCookieJar cookieJar,

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

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

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_format_quote_accent" android:state_selected="true"/>
<item android:drawable="@drawable/ic_format_quote_grey" android:state_selected="false"/>
</selector>

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

@ -106,6 +106,13 @@
android:maxLines="1" android:maxLines="1"
android:text="@string/subject" android:text="@string/subject"
/> />
<ImageButton
android:id="@+id/toggle_quote_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/ic_toggle_quote_bg"/>
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
@ -141,9 +148,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="12dp" android:layout_height="12dp"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:weightSum="0"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"> android:visibility="gone"
android:weightSum="0">
</LinearLayout> </LinearLayout>
<TextView <TextView

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

@ -10,26 +10,6 @@
<color name="card_background">#FFFFFF</color> <color name="card_background">#FFFFFF</color>
<color name="divider">#8B8B8B</color> <color name="divider">#8B8B8B</color>
<!--Lime-->
<!--<color name="primary">#CDDC39</color>
<color name="primary_dark">#AFB42B</color>
<color name="primary_light">#F0F4C3</color>
<color name="accent">#FFC107</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#757575</color>
<color name="card_background">#212121</color>
<color name="divider">#BDBDBD</color>-->
<!--Cyan-->
<!--<color name="primary">#00BCD4</color>
<color name="primary_dark">#0097A7</color>
<color name="primary_light">#B2EBF2</color>
<color name="accent">#009688</color>
<color name="primary_text">#464646</color>
<color name="secondary_text">#757575</color>
<color name="card_background">#FFFFFF</color>
<color name="divider">#BDBDBD</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="black">#000000</color>

Loading…
Cancel
Save