@ -5,12 +5,16 @@ import java.util.List;
import org.floens.chan.R ;
import org.floens.chan.R ;
import org.floens.chan.activity.ReplyActivity ;
import org.floens.chan.activity.ReplyActivity ;
import org.floens.chan.database.DatabaseManager ;
import org.floens.chan.fragment.PostRepliesFragment ;
import org.floens.chan.fragment.PostRepliesFragment ;
import org.floens.chan.fragment.ReplyFragment ;
import org.floens.chan.fragment.ReplyFragment ;
import org.floens.chan.manager.ReplyManager.DeleteListener ;
import org.floens.chan.manager.ReplyManager.DeleteResponse ;
import org.floens.chan.model.Loadable ;
import org.floens.chan.model.Loadable ;
import org.floens.chan.model.Pin ;
import org.floens.chan.model.Pin ;
import org.floens.chan.model.Post ;
import org.floens.chan.model.Post ;
import org.floens.chan.model.PostLinkable ;
import org.floens.chan.model.PostLinkable ;
import org.floens.chan.model.SavedReply ;
import org.floens.chan.net.ThreadLoader ;
import org.floens.chan.net.ThreadLoader ;
import org.floens.chan.utils.ChanPreferences ;
import org.floens.chan.utils.ChanPreferences ;
import org.floens.chan.utils.Logger ;
import org.floens.chan.utils.Logger ;
@ -20,17 +24,20 @@ import org.floens.chan.watch.WatchLogic.WatchListener;
import android.app.Activity ;
import android.app.Activity ;
import android.app.AlertDialog ;
import android.app.AlertDialog ;
import android.app.FragmentTransaction ;
import android.app.FragmentTransaction ;
import android.app.ProgressDialog ;
import android.content.ClipData ;
import android.content.ClipData ;
import android.content.ClipboardManager ;
import android.content.ClipboardManager ;
import android.content.Context ;
import android.content.Context ;
import android.content.DialogInterface ;
import android.content.DialogInterface ;
import android.content.DialogInterface.OnClickListener ;
import android.content.Intent ;
import android.content.Intent ;
import android.net.Uri ;
import android.net.Uri ;
import android.text.TextUtils ;
import android.text.TextUtils ;
import android.util.Log ;
import android.view.Gravity ;
import android.view.Gravity ;
import android.widget.CheckBox ;
import android.widget.LinearLayout.LayoutParams ;
import android.widget.LinearLayout.LayoutParams ;
import android.widget.TextView ;
import android.widget.TextView ;
import android.widget.Toast ;
import com.android.volley.NetworkError ;
import com.android.volley.NetworkError ;
import com.android.volley.NoConnectionError ;
import com.android.volley.NoConnectionError ;
@ -44,6 +51,8 @@ import com.android.volley.VolleyError;
* onDestroy , onPause and onResume must be called from the activity / fragment
* onDestroy , onPause and onResume must be called from the activity / fragment
* /
* /
public class ThreadManager implements ThreadLoader . ThreadLoaderListener , WatchListener {
public class ThreadManager implements ThreadLoader . ThreadLoaderListener , WatchListener {
private static final String TAG = "ThreadManager" ;
private final Activity activity ;
private final Activity activity ;
private final ThreadLoader threadLoader ;
private final ThreadLoader threadLoader ;
private final ThreadManager . ThreadListener threadListener ;
private final ThreadManager . ThreadListener threadListener ;
@ -81,7 +90,7 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
@Override
@Override
public void onWatchReloadRequested ( ) {
public void onWatchReloadRequested ( ) {
Logger . test ( "ThreadManager r eload requested") ;
Logger . d ( TAG , "R eload requested") ;
if ( ! threadLoader . isLoading ( ) ) {
if ( ! threadLoader . isLoading ( ) ) {
threadLoader . start ( loadable ) ;
threadLoader . start ( loadable ) ;
@ -157,7 +166,7 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
public void reload ( ) {
public void reload ( ) {
if ( loadable = = null ) {
if ( loadable = = null ) {
Log . e ( "Chan" , "ThreadManager: loadable null" ) ;
Logger . e ( TAG , "ThreadManager: loadable null" ) ;
} else {
} else {
if ( loadable . isBoardMode ( ) ) {
if ( loadable . isBoardMode ( ) ) {
loadable . no = 0 ;
loadable . no = 0 ;
@ -173,7 +182,7 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
if ( threadLoader . isLoading ( ) ) return ;
if ( threadLoader . isLoading ( ) ) return ;
if ( loadable = = null ) {
if ( loadable = = null ) {
Log . e ( "Chan" , "ThreadManager: loadable null" ) ;
Logger . e ( TAG , "ThreadManager: loadable null" ) ;
} else {
} else {
if ( loadable . isBoardMode ( ) ) {
if ( loadable . isBoardMode ( ) ) {
if ( ! endOfLine ) {
if ( ! endOfLine ) {
@ -200,7 +209,19 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
public void onPostLongClicked ( final Post post ) {
public void onPostLongClicked ( final Post post ) {
AlertDialog . Builder builder = new AlertDialog . Builder ( activity ) ;
AlertDialog . Builder builder = new AlertDialog . Builder ( activity ) ;
builder . setItems ( R . array . post_options , new DialogInterface . OnClickListener ( ) {
String [ ] items = null ;
String [ ] temp = activity . getResources ( ) . getStringArray ( R . array . post_options ) ;
// Only add the delete option when the post is a saved reply
if ( DatabaseManager . getInstance ( ) . isSavedReply ( post . board , post . no ) ) {
items = new String [ temp . length + 1 ] ;
System . arraycopy ( temp , 0 , items , 0 , temp . length ) ;
items [ items . length - 1 ] = activity . getString ( R . string . delete ) ;
} else {
items = temp ;
}
builder . setItems ( items , new DialogInterface . OnClickListener ( ) {
@Override
@Override
public void onClick ( DialogInterface dialog , int which ) {
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
switch ( which ) {
@ -217,7 +238,10 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
showPostLinkables ( post ) ;
showPostLinkables ( post ) ;
break ;
break ;
case 4 : // Copy text
case 4 : // Copy text
copyText ( post . comment . toString ( ) ) ;
copyToClipboard ( post . comment . toString ( ) ) ;
break ;
case 5 : // Delete
deletePost ( post ) ;
break ;
break ;
}
}
}
}
@ -242,11 +266,11 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
}
}
/ * *
/ * *
* Returns an TextView containing the appropiate error message
* Returns an TextView containing the appropr iate error message
* @param error
* @param error
* @return
* @return
* /
* /
public TextView getTextViewError ( VolleyError error ) {
public TextView getLoadError TextView ( VolleyError error ) {
String errorMessage = "" ;
String errorMessage = "" ;
if ( ( error instanceof NoConnectionError ) | | ( error instanceof NetworkError ) ) {
if ( ( error instanceof NoConnectionError ) | | ( error instanceof NetworkError ) ) {
@ -266,19 +290,21 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
return view ;
return view ;
}
}
private void copyText ( String comment ) {
private void copyToClipboard ( String comment ) {
ClipboardManager clipboard = ( ClipboardManager ) activity . getSystemService ( Context . CLIPBOARD_SERVICE ) ;
ClipboardManager clipboard = ( ClipboardManager ) activity . getSystemService ( Context . CLIPBOARD_SERVICE ) ;
ClipData clip = ClipData . newPlainText ( "p ost text" , comment ) ;
ClipData clip = ClipData . newPlainText ( "P ost text" , comment ) ;
clipboard . setPrimaryClip ( clip ) ;
clipboard . setPrimaryClip ( clip ) ;
}
}
private void showPostInfo ( Post post ) {
private void showPostInfo ( Post post ) {
String text = "Time: " + post . date ;
String text = "" ;
if ( post . hasImage ) {
if ( post . hasImage ) {
text + = "\n File: " + post . filename + " \nSize: " + post . imageWidth + "x" + post . imageHeight ;
text + = "File: " + post . filename + " \nSize: " + post . imageWidth + "x" + post . imageHeight + "\n\n" ;
}
}
text + = "Time: " + post . date ;
if ( ! TextUtils . isEmpty ( post . id ) ) {
if ( ! TextUtils . isEmpty ( post . id ) ) {
text + = "\nId: " + post . id ;
text + = "\nId: " + post . id ;
}
}
@ -467,6 +493,69 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
currentPopupFragment = null ;
currentPopupFragment = null ;
}
}
private void deletePost ( final Post post ) {
final CheckBox view = new CheckBox ( activity ) ;
view . setText ( R . string . delete_image_only ) ;
int padding = activity . getResources ( ) . getDimensionPixelSize ( R . dimen . general_padding ) ;
view . setPadding ( padding , padding , padding , padding ) ;
new AlertDialog . Builder ( activity )
. setTitle ( R . string . delete_confirm )
. setView ( view )
. setPositiveButton ( R . string . delete , new OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
doDeletePost ( post , view . isChecked ( ) ) ;
}
} )
. setNegativeButton ( R . string . cancel , new OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
}
} )
. show ( ) ;
}
private void doDeletePost ( Post post , boolean onlyImageDelete ) {
SavedReply reply = DatabaseManager . getInstance ( ) . getSavedReply ( post . board , post . no ) ;
if ( reply = = null ) {
/ * reply = new SavedReply ( ) ;
reply . board = "g" ;
reply . no = 1234 ;
reply . password = "boom" ; * /
return ;
}
final ProgressDialog dialog = ProgressDialog . show ( activity , null , activity . getString ( R . string . delete_wait ) ) ;
ReplyManager . getInstance ( ) . sendDelete ( reply , onlyImageDelete , new DeleteListener ( ) {
@Override
public void onResponse ( DeleteResponse response ) {
dialog . dismiss ( ) ;
if ( response . isNetworkError | | response . isUserError ) {
int resId = 0 ;
if ( response . isTooSoonError ) {
resId = R . string . delete_too_soon ;
} else if ( response . isInvalidPassword ) {
resId = R . string . delete_password_incorrect ;
} else if ( response . isTooOldError ) {
resId = R . string . delete_too_old ;
} else {
resId = R . string . delete_fail ;
}
Toast . makeText ( activity , resId , Toast . LENGTH_LONG ) . show ( ) ;
} else if ( response . isSuccessful ) {
Toast . makeText ( activity , R . string . delete_success , Toast . LENGTH_SHORT ) . show ( ) ;
} else {
Toast . makeText ( activity , R . string . delete_fail , Toast . LENGTH_LONG ) . show ( ) ;
}
}
} ) ;
}
public interface ThreadListener {
public interface ThreadListener {
public void onThreadLoaded ( List < Post > result ) ;
public void onThreadLoaded ( List < Post > result ) ;
public void onThreadLoadError ( VolleyError error ) ;
public void onThreadLoadError ( VolleyError error ) ;