@ -8,6 +8,7 @@ import android.content.DialogInterface;
@@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.net.Uri ;
import android.support.annotation.NonNull ;
import android.support.v7.app.AlertDialog ;
import android.text.TextUtils ;
import android.view.View ;
import android.widget.ArrayAdapter ;
import android.widget.AutoCompleteTextView ;
@ -56,7 +57,7 @@ public class LightningDialogBuilder {
@@ -56,7 +57,7 @@ public class LightningDialogBuilder {
* @param context used to show the dialog
* @param url the long pressed url
* /
public void showLongPressedDialogForBookmarkUrl ( @NonNull final Context context , @NonNull final String url ) {
public void showLongPressedDialogForBookmarkUrl ( @NonNull final Activity context , @NonNull final String url ) {
final HistoryItem item ;
if ( url . startsWith ( Constants . FILE ) & & url . endsWith ( BookmarkPage . FILENAME ) ) {
// TODO hacky, make a better bookmark mechanism in the future
@ -80,35 +81,28 @@ public class LightningDialogBuilder {
@@ -80,35 +81,28 @@ public class LightningDialogBuilder {
}
}
public void showLongPressedDialogForBookmarkUrl ( @NonNull final Context context , @NonNull final HistoryItem item ) {
final DialogInterface . OnClickListener dialogClickListener =
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
case DialogInterface . BUTTON_POSITIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( item . getUrl ( ) ) ) ;
break ;
case DialogInterface . BUTTON_NEGATIVE :
if ( mBookmarkManager . deleteBookmark ( item ) ) {
mEventBus . post ( new BookmarkEvents . Deleted ( item ) ) ;
}
break ;
case DialogInterface . BUTTON_NEUTRAL :
showEditBookmarkDialog ( context , item ) ;
break ;
}
public void showLongPressedDialogForBookmarkUrl ( @NonNull final Activity context , @NonNull final HistoryItem item ) {
BrowserDialog . show ( context , R . string . action_bookmarks ,
new BrowserDialog . Item ( R . string . action_new_tab ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( item . getUrl ( ) ) ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_delete ) {
@Override
public void onClick ( ) {
if ( mBookmarkManager . deleteBookmark ( item ) ) {
mEventBus . post ( new BookmarkEvents . Deleted ( item ) ) ;
}
} ;
AlertDialog . Builder builder = new AlertDialog . Builder ( context ) ;
builder . setTitle ( R . string . action_bookmarks )
. setMessage ( R . string . dialog_bookmark )
. setCancelable ( true )
. setPositiveButton ( R . string . action_new_tab , dialogClickListener )
. setNegativeButton ( R . string . action_delete , dialogClickListener )
. setNeutralButton ( R . string . action_edit , dialogClickListener )
. show ( ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_edit ) {
@Override
public void onClick ( ) {
showEditBookmarkDialog ( context , item ) ;
}
} ) ;
}
private void showEditBookmarkDialog ( @NonNull final Context context , @NonNull final HistoryItem item ) {
@ -120,191 +114,145 @@ public class LightningDialogBuilder {
@@ -120,191 +114,145 @@ public class LightningDialogBuilder {
final EditText getUrl = ( EditText ) dialogLayout . findViewById ( R . id . bookmark_url ) ;
getUrl . setText ( item . getUrl ( ) ) ;
final AutoCompleteTextView getFolder =
( AutoCompleteTextView ) dialogLayout . findViewById ( R . id . bookmark_folder ) ;
( AutoCompleteTextView ) dialogLayout . findViewById ( R . id . bookmark_folder ) ;
getFolder . setHint ( R . string . folder ) ;
getFolder . setText ( item . getFolder ( ) ) ;
final List < String > folders = mBookmarkManager . getFolderTitles ( ) ;
final ArrayAdapter < String > suggestionsAdapter = new ArrayAdapter < > ( context ,
android . R . layout . simple_dropdown_item_1line , folders ) ;
android . R . layout . simple_dropdown_item_1line , folders ) ;
getFolder . setThreshold ( 1 ) ;
getFolder . setAdapter ( suggestionsAdapter ) ;
editBookmarkDialog . setView ( dialogLayout ) ;
editBookmarkDialog . setPositiveButton ( context . getString ( R . string . action_ok ) ,
new DialogInterface . OnClickListener ( ) {
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
HistoryItem editedItem = new HistoryItem ( ) ;
editedItem . setTitle ( getTitle . getText ( ) . toString ( ) ) ;
editedItem . setUrl ( getUrl . getText ( ) . toString ( ) ) ;
editedItem . setUrl ( getUrl . getText ( ) . toString ( ) ) ;
editedItem . setFolder ( getFolder . getText ( ) . toString ( ) ) ;
mBookmarkManager . editBookmark ( item , editedItem ) ;
mEventBus . post ( new BookmarkEvents . BookmarkChanged ( item , editedItem ) ) ;
}
} ) ;
@Override
public void onClick ( DialogInterface dialog , int which ) {
HistoryItem editedItem = new HistoryItem ( ) ;
editedItem . setTitle ( getTitle . getText ( ) . toString ( ) ) ;
editedItem . setUrl ( getUrl . getText ( ) . toString ( ) ) ;
editedItem . setUrl ( getUrl . getText ( ) . toString ( ) ) ;
editedItem . setFolder ( getFolder . getText ( ) . toString ( ) ) ;
mBookmarkManager . editBookmark ( item , editedItem ) ;
mEventBus . post ( new BookmarkEvents . BookmarkChanged ( item , editedItem ) ) ;
}
} ) ;
editBookmarkDialog . show ( ) ;
}
public void showBookmarkFolderLongPressedDialog ( @NonNull final Context context , @NonNull final HistoryItem item ) {
// assert item.isFolder();
final DialogInterface . OnClickListener dialogClickListener =
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
case DialogInterface . BUTTON_POSITIVE :
showRenameFolderDialog ( context , item ) ;
break ;
public void showBookmarkFolderLongPressedDialog ( @NonNull final Activity context , @NonNull final HistoryItem item ) {
case DialogInterface . BUTTON_NEGATIVE :
mBookmarkManager . deleteFolder ( item . getTitle ( ) ) ;
// setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
mEventBus . post ( new BookmarkEvents . Deleted ( item ) ) ;
break ;
}
}
} ;
final AlertDialog . Builder builder = new AlertDialog . Builder ( context ) ;
builder . setTitle ( R . string . action_folder )
. setMessage ( R . string . dialog_folder )
. setCancelable ( true )
. setPositiveButton ( R . string . action_rename , dialogClickListener )
. setNegativeButton ( R . string . action_delete , dialogClickListener )
. show ( ) ;
BrowserDialog . show ( context , R . string . action_folder ,
new BrowserDialog . Item ( R . string . action_rename ) {
@Override
public void onClick ( ) {
showRenameFolderDialog ( context , item ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_delete ) {
@Override
public void onClick ( ) {
mBookmarkManager . deleteFolder ( item . getTitle ( ) ) ;
mEventBus . post ( new BookmarkEvents . Deleted ( item ) ) ;
}
} ) ;
}
private void showRenameFolderDialog ( @NonNull final Context context , @NonNull final HistoryItem item ) {
// assert item.isFolder();
final AlertDialog . Builder editFolderDialog = new AlertDialog . Builder ( context ) ;
editFolderDialog . setTitle ( R . string . title_rename_folder ) ;
final EditText getTitle = new EditText ( context ) ;
getTitle . setHint ( R . string . hint_title ) ;
getTitle . setText ( item . getTitle ( ) ) ;
getTitle . setSingleLine ( ) ;
LinearLayout layout = new LinearLayout ( context ) ;
layout . setOrientation ( LinearLayout . VERTICAL ) ;
int padding = Utils . dpToPx ( 10 ) ;
layout . setPadding ( padding , padding , padding , padding ) ;
layout . addView ( getTitle ) ;
editFolderDialog . setView ( layout ) ;
editFolderDialog . setPositiveButton ( context . getString ( R . string . action_ok ) ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
private void showRenameFolderDialog ( @NonNull final Activity context , @NonNull final HistoryItem item ) {
BrowserDialog . showEditText ( context , R . string . title_rename_folder ,
R . string . hint_title , item . getTitle ( ) ,
R . string . action_ok , new BrowserDialog . EditorListener ( ) {
@Override
public void onClick ( String text ) {
if ( ! TextUtils . isEmpty ( text ) ) {
final String oldTitle = item . getTitle ( ) ;
final String newTitle = getTitle . getText ( ) . toString ( ) ;
final HistoryItem editedItem = new HistoryItem ( ) ;
editedItem . setTitle ( newTi tl e) ;
editedItem . setUrl ( Constants . FOLDER + newTi tl e) ;
editedItem . setTitle ( text ) ;
editedItem . setUrl ( Constants . FOLDER + text ) ;
editedItem . setFolder ( item . getFolder ( ) ) ;
editedItem . setIsFolder ( true ) ;
mBookmarkManager . renameFolder ( oldTitle , newTi tl e) ;
mBookmarkManager . renameFolder ( oldTitle , text ) ;
mEventBus . post ( new BookmarkEvents . BookmarkChanged ( item , editedItem ) ) ;
}
} ) ;
editFolderDialog . show ( ) ;
}
} ) ;
}
public void showLongPressedHistoryLinkDialog ( final Context context , @NonNull final String url ) {
DialogInterface . OnClickListener dialogClickListener = new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
case DialogInterface . BUTTON_POSITIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
break ;
case DialogInterface . BUTTON_NEGATIVE :
BrowserApp . getIOThread ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
mHistoryDatabase . deleteHistoryItem ( url ) ;
// openHistory();
mEventBus . post ( new BrowserEvents . OpenHistoryInCurrentTab ( ) ) ;
}
} ) ;
break ;
case DialogInterface . BUTTON_NEUTRAL :
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
break ;
default :
break ;
public void showLongPressedHistoryLinkDialog ( final Activity context , @NonNull final String url ) {
BrowserDialog . show ( context , R . string . action_history ,
new BrowserDialog . Item ( R . string . action_new_tab ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
}
}
} ;
AlertDialog . Builder builder = new AlertDialog . Builder ( context ) ;
builder . setTitle ( R . string . action_history )
. setMessage ( R . string . dialog_history_long_press )
. setCancelable ( true )
. setPositiveButton ( R . string . action_new_tab , dialogClickListener )
. setNegativeButton ( R . string . action_delete , dialogClickListener )
. setNeutralButton ( R . string . action_open , dialogClickListener )
. show ( ) ;
} ,
new BrowserDialog . Item ( R . string . action_delete ) {
@Override
public void onClick ( ) {
BrowserApp . getIOThread ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
mHistoryDatabase . deleteHistoryItem ( url ) ;
// openHistory();
mEventBus . post ( new BrowserEvents . OpenHistoryInCurrentTab ( ) ) ;
}
} ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_open ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
}
} ) ;
}
// TODO There should be a way in which we do not need an activity reference to dowload a file
public void showLongPressImageDialog ( @NonNull final Activity activity , @NonNull final String url ,
@NonNull final String userAgent ) {
DialogInterface . OnClickListener dialogClickListener = new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
case DialogInterface . BUTTON_POSITIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
break ;
case DialogInterface . BUTTON_NEGATIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
break ;
case DialogInterface . BUTTON_NEUTRAL :
Utils . downloadFile ( activity , mPreferenceManager , url , userAgent , "attachment" ) ;
break ;
BrowserDialog . show ( activity , url . replace ( Constants . HTTP , "" ) ,
new BrowserDialog . Item ( R . string . action_new_tab ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
}
}
} ;
AlertDialog . Builder builder = new AlertDialog . Builder ( activity ) ;
builder . setTitle ( url . replace ( Constants . HTTP , "" ) )
. setCancelable ( true )
. setMessage ( R . string . dialog_image )
. setPositiveButton ( R . string . action_new_tab , dialogClickListener )
. setNegativeButton ( R . string . action_open , dialogClickListener )
. setNeutralButton ( R . string . action_download , dialogClickListener )
. show ( ) ;
} ,
new BrowserDialog . Item ( R . string . action_open ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_download ) {
@Override
public void onClick ( ) {
Utils . downloadFile ( activity , mPreferenceManager , url , userAgent , "attachment" ) ;
}
} ) ;
}
public void showLongPressLinkDialog ( @NonNull final Context context , final String url ) {
DialogInterface . OnClickListener dialogClickListener = new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
switch ( which ) {
case DialogInterface . BUTTON_POSITIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
break ;
case DialogInterface . BUTTON_NEGATIVE :
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
break ;
case DialogInterface . BUTTON_NEUTRAL :
ClipboardManager clipboard = ( ClipboardManager ) context . getSystemService ( Context . CLIPBOARD_SERVICE ) ;
ClipData clip = ClipData . newPlainText ( "label" , url ) ;
clipboard . setPrimaryClip ( clip ) ;
break ;
public void showLongPressLinkDialog ( @NonNull final Activity context , final String url ) {
BrowserDialog . show ( context , url ,
new BrowserDialog . Item ( R . string . action_new_tab ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInNewTab ( url ) ) ;
}
}
} ;
AlertDialog . Builder builder = new AlertDialog . Builder ( context ) ; // dialog
builder . setTitle ( url )
. setCancelable ( true )
. setMessage ( R . string . dialog_link )
. setPositiveButton ( R . string . action_new_tab , dialogClickListener )
. setNegativeButton ( R . string . action_open , dialogClickListener )
. setNeutralButton ( R . string . action_copy , dialogClickListener )
. show ( ) ;
} ,
new BrowserDialog . Item ( R . string . action_open ) {
@Override
public void onClick ( ) {
mEventBus . post ( new BrowserEvents . OpenUrlInCurrentTab ( url ) ) ;
}
} ,
new BrowserDialog . Item ( R . string . action_copy ) {
@Override
public void onClick ( ) {
ClipboardManager clipboard = ( ClipboardManager ) context . getSystemService ( Context . CLIPBOARD_SERVICE ) ;
ClipData clip = ClipData . newPlainText ( "label" , url ) ;
clipboard . setPrimaryClip ( clip ) ;
}
} ) ;
}
}