diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-06-18 01:18:45 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-06-18 01:18:45 +0900 |
commit | 04d2ae52f87003fcf4659fcce4cc95d2303e2984 (patch) | |
tree | d8e9307446d06b0ad24ab7bb495d23cbd43a737c /app/src/main/java/net/lacolaco/smileessence | |
parent | d5bec3ed0dc5b215963ceece99bed6ed1d0d9d29 (diff) | |
download | SmileEssence-04d2ae52f87003fcf4659fcce4cc95d2303e2984.tar.gz |
*MenuDialogFragment: refactor common code
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence')
12 files changed, 91 insertions, 186 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java index de5b4ac2..e8b3e438 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -301,17 +301,6 @@ public class SearchFragment extends CustomListFragment implements View.OnClickLi } DialogHelper.showDialog(mainActivity, new SelectSearchQueryDialogFragment() { @Override - protected void deleteQuery(CommandOpenSearch command) { - super.deleteQuery(command); - if (editText.getText().toString().contentEquals(command.getQuery().query)) { - editText.setText(""); - mainActivity.setLastSearch(""); - } else { - mainActivity.setLastSearch(editText.getText().toString()); - } - } - - @Override protected void executeCommand(Command command) { super.executeCommand(command); SearchQuery query = ((CommandOpenSearch) command).getQuery(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/ChooseTemplateDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/ChooseTemplateDialogFragment.java index 425e95c7..c69b02cc 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/ChooseTemplateDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/ChooseTemplateDialogFragment.java @@ -25,17 +25,10 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.os.Bundle; -import android.view.View; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.post.PostCommandUseTemplate; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Template; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; @@ -47,24 +40,14 @@ public class ChooseTemplateDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + List<Command> commands = getCommands(activity); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); - listView.setOnItemClickListener(onItemClickListener); - - return new AlertDialog.Builder(activity) - .setView(body) - .setCancelable(true) - .create(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/HashtagDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/HashtagDialogFragment.java index 3ba8ee5e..63ae6c54 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/HashtagDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/HashtagDialogFragment.java @@ -25,19 +25,14 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandPasteToPost; import net.lacolaco.smileessence.command.CommandSaveAsTemplate; import net.lacolaco.smileessence.command.CommandSearchOnTwitter; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; import java.util.ArrayList; @@ -64,23 +59,23 @@ public class HashtagDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + String text = getHashtagText(); List<Command> commands = getCommands(activity, text); Command.filter(commands); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); - listView.setOnItemClickListener(onItemClickListener); + } - return new AlertDialog.Builder(activity).setView(body).setTitle(text).setCancelable(true).create(); + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.setTitle(getHashtagText()); + return dialog; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MenuDialogFragment.java index 049ed55a..f16da40d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MenuDialogFragment.java @@ -24,16 +24,35 @@ package net.lacolaco.smileessence.view.dialog; +import android.app.AlertDialog; +import android.app.Dialog; +import android.os.Bundle; import android.view.View; import android.widget.AdapterView; +import android.widget.ListView; import net.lacolaco.smileessence.R; +import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.IConfirmable; +import net.lacolaco.smileessence.view.adapter.CustomListAdapter; -public abstract class MenuDialogFragment extends StackableDialogFragment{ +public abstract class MenuDialogFragment extends StackableDialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final MainActivity activity = (MainActivity) getActivity(); + View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); + ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); + final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); + listView.setAdapter(adapter); + listView.setOnItemClickListener(onItemClickListener); - // ------------------------------ FIELDS ------------------------------ + setMenuItems(adapter); + + return new AlertDialog.Builder(activity).setView(body).create(); + } + + protected abstract void setMenuItems(final CustomListAdapter<Command> adapter); protected final AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() { @Override diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java index 9b513d01..c4fd6028 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java @@ -25,13 +25,8 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenHashtagDialog; @@ -71,23 +66,10 @@ public class MessageMenuDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - protected void executeCommand(Command command) { - dismiss(); - command.execute(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { + protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); - listView.setOnItemClickListener(onItemClickListener); - - final AlertDialog alertDialog = new AlertDialog.Builder(activity).setView(body).create(); TwitterUtils.tryGetMessage(account, getMessageID(), new TwitterUtils.MessageCallback() { @Override public void success(DirectMessage message) { @@ -104,7 +86,6 @@ public class MessageMenuDialogFragment extends MenuDialogFragment { dismiss(); } }); - return alertDialog; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/PostMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/PostMenuDialogFragment.java index 527a5645..3a670a8d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/PostMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/PostMenuDialogFragment.java @@ -25,11 +25,6 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.os.Bundle; -import android.view.View; -import android.widget.ListView; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; @@ -38,7 +33,6 @@ import net.lacolaco.smileessence.command.CommandOpenTemplateList; import net.lacolaco.smileessence.command.post.PostCommandMakeAnonymous; import net.lacolaco.smileessence.command.post.PostCommandMorse; import net.lacolaco.smileessence.command.post.PostCommandZekamashi; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; @@ -52,29 +46,19 @@ public class PostMenuDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + List<Command> commands = getCommands(activity); Command.filter(commands); if (commands.isEmpty()) { Notificator.publish(getActivity(), R.string.notice_no_command_exists); - return new DisposeDialog(getActivity()); + dismiss(); } - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); - listView.setOnItemClickListener(onItemClickListener); - - return new AlertDialog.Builder(activity) - .setView(body) - .setCancelable(true) - .create(); } @Override diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java index de9cacac..e0f51d69 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java @@ -25,13 +25,8 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.status.StatusCommandTextQuote; @@ -66,17 +61,11 @@ public class QuoteDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { + protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); + final Account account = activity.getCurrentAccount(); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); - listView.setOnItemClickListener(onItemClickListener); - Account account = activity.getCurrentAccount(); - long statusID = getStatusID(); - TwitterUtils.tryGetStatus(account, statusID, new TwitterUtils.StatusCallback() { + TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() { @Override public void success(Status status) { List<Command> commands = getCommands(activity, status); @@ -92,7 +81,6 @@ public class QuoteDialogFragment extends MenuDialogFragment { dismiss(); } }); - return new AlertDialog.Builder(activity).setView(body).setCancelable(true).create(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectImageDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectImageDialogFragment.java index 9d01f6ca..82d00472 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectImageDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectImageDialogFragment.java @@ -24,20 +24,16 @@ package net.lacolaco.smileessence.view.dialog; -import android.app.AlertDialog; import android.app.Dialog; import android.content.ContentValues; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; -import android.view.View; -import android.widget.ListView; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.util.IntentUtils; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; @@ -49,21 +45,22 @@ public class SelectImageDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + List<Command> commands = getCommands(activity); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); + Command.filter(commands); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); - listView.setOnItemClickListener(onItemClickListener); + } - return new AlertDialog.Builder(activity).setView(body).setTitle(R.string.dialog_title_select_image).setCancelable(true).create(); + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.setTitle(R.string.dialog_title_select_image); + return dialog; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java index 637a0d37..8d7c9728 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java @@ -35,7 +35,6 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenSearch; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.SearchQuery; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; @@ -45,43 +44,60 @@ import java.util.List; public class SelectSearchQueryDialogFragment extends MenuDialogFragment implements AdapterView.OnItemLongClickListener { - // ------------------------ INTERFACE METHODS ------------------------ - - // --------------------- Interface OnItemLongClickListener --------------------- @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final CommandOpenSearch command = (CommandOpenSearch) parent.getItemAtPosition(position); + final CustomListAdapter<Command> adapter = (CustomListAdapter<Command>) parent.getAdapter(); + ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_delete_query), new Runnable() { @Override public void run() { - deleteQuery(command); + adapter.removeItem(command); + adapter.update(); + + command.getQuery().delete(); + Notificator.publish(getActivity(), R.string.notice_search_query_deleted); } }, false); + return true; } // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + List<Command> commands = getCommands(activity); Command.filter(commands); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final MainActivity activity = (MainActivity) getActivity(); + View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); + ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); + final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); + listView.setAdapter(adapter); listView.setOnItemClickListener(onItemClickListener); + + // addition listView.setOnItemLongClickListener(this); - return new AlertDialog.Builder(activity).setView(body).setTitle(R.string.dialog_title_select_search_query).setCancelable(true).create(); + setMenuItems(adapter); + + // addition + return new AlertDialog.Builder(activity) + .setView(body) + .setTitle(R.string.dialog_title_select_search_query) + .create(); } // -------------------------- OTHER METHODS -------------------------- @@ -96,11 +112,4 @@ public class SelectSearchQueryDialogFragment extends MenuDialogFragment implemen } return commands; } - - protected void deleteQuery(CommandOpenSearch command) { - command.getQuery().delete(); - Notificator.publish(getActivity(), R.string.notice_search_query_deleted); - ((MainActivity) getActivity()).openSearchPage(""); - dismiss(); - } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java index b38f941b..514131f3 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectUserListDialogFragment.java @@ -24,18 +24,14 @@ package net.lacolaco.smileessence.view.dialog; -import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.ListView; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenUserList; import net.lacolaco.smileessence.data.UserListCache; -import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; import java.util.ArrayList; @@ -46,22 +42,22 @@ public class SelectUserListDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - MainActivity activity = (MainActivity) getActivity(); - Account account = activity.getCurrentAccount(); + protected void setMenuItems(final CustomListAdapter<Command> adapter) { + final MainActivity activity = (MainActivity) getActivity(); + List<Command> commands = getCommands(activity); Command.filter(commands); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); for (Command command : commands) { adapter.addToBottom(command); } adapter.update(); - listView.setOnItemClickListener(onItemClickListener); + } - return new AlertDialog.Builder(activity).setView(body).setTitle(R.string.dialog_title_select_userlist).setCancelable(true).create(); + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.setTitle(R.string.dialog_title_select_userlist); + return dialog; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java index 5f362d42..667578b7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java @@ -25,13 +25,8 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenHashtagDialog; @@ -69,19 +64,11 @@ public class StatusMenuDialogFragment extends MenuDialogFragment { } // ------------------------ OVERRIDE METHODS ------------------------ - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { + protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); - listView.setOnItemClickListener(onItemClickListener); - - final AlertDialog alertDialog = new AlertDialog.Builder(activity).setView(body).create(); TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() { @Override public void success(Status status) { @@ -98,7 +85,6 @@ public class StatusMenuDialogFragment extends MenuDialogFragment { dismiss(); } }); - return alertDialog; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java index e9bf12a5..ad1efc89 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java @@ -25,14 +25,8 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; -import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandSearchOnTwitter; @@ -66,14 +60,9 @@ public class UserMenuDialogFragment extends MenuDialogFragment { // ------------------------ OVERRIDE METHODS ------------------------ @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { + protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - View body = activity.getLayoutInflater().inflate(R.layout.dialog_menu_list, null); - ListView listView = (ListView) body.findViewById(R.id.listview_dialog_menu_list); - final CustomListAdapter<Command> adapter = new CustomListAdapter<>(activity, Command.class); - listView.setAdapter(adapter); - listView.setOnItemClickListener(onItemClickListener); TwitterUtils.tryGetUser(account, getUserID(), new TwitterUtils.UserCallback() { @Override @@ -91,17 +80,6 @@ public class UserMenuDialogFragment extends MenuDialogFragment { dismiss(); } }); - - return new AlertDialog.Builder(activity) - .setView(body) - .setCancelable(true) - .create(); - } - - @Override - protected void onItemClick(AdapterView<?> adapterView, int i) { - dismiss(); - super.onItemClick(adapterView, i); } // -------------------------- OTHER METHODS -------------------------- |