From 9db537d339faa3ad44dfdcadb23f4c14bd8aceb4 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 5 Oct 2017 15:58:59 +0900 Subject: kotlin work part. 1 --- .../net/lacolaco/smileessence/command/Command.java | 44 -------------- .../net/lacolaco/smileessence/command/Command.kt | 35 +++++++++++ .../smileessence/command/CommandAddHashtag.java | 56 ------------------ .../smileessence/command/CommandAddHashtag.kt | 48 +++++++++++++++ .../smileessence/command/CommandOpenURL.java | 57 ------------------ .../smileessence/command/CommandOpenURL.kt | 46 +++++++++++++++ .../command/CommandOpenUserDetail.java | 68 ---------------------- .../smileessence/command/CommandOpenUserDetail.kt | 58 ++++++++++++++++++ 8 files changed, 187 insertions(+), 225 deletions(-) delete mode 100644 app/src/main/java/net/lacolaco/smileessence/command/Command.java create mode 100644 app/src/main/java/net/lacolaco/smileessence/command/Command.kt delete mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.java create mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.kt delete mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.java create mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt delete mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java create mode 100644 app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.kt (limited to 'app/src/main/java/net/lacolaco/smileessence/command') diff --git a/app/src/main/java/net/lacolaco/smileessence/command/Command.java b/app/src/main/java/net/lacolaco/smileessence/command/Command.java deleted file mode 100644 index 0225b886..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/command/Command.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.command; - -import net.lacolaco.smileessence.activity.MainActivity; - -public abstract class Command { - private final MainActivity activity; - - public Command(MainActivity activity) { - this.activity = activity; - } - - protected MainActivity getActivity() { - return activity; - } - - public abstract boolean execute(); - - public abstract String getText(); - -} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/Command.kt b/app/src/main/java/net/lacolaco/smileessence/command/Command.kt new file mode 100644 index 00000000..98183dc7 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/command/Command.kt @@ -0,0 +1,35 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2012-2014 lacolaco.net + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.lacolaco.smileessence.command + +import net.lacolaco.smileessence.activity.MainActivity + +abstract class Command(protected val activity: MainActivity) { + + abstract fun execute(): Boolean + + abstract val text: String + +} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.java b/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.java deleted file mode 100644 index b2de5c21..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.command; - -import net.lacolaco.smileessence.activity.MainActivity; - -public class CommandAddHashtag extends Command { - - // ------------------------------ FIELDS ------------------------------ - - private final String hashtag; - - // --------------------------- CONSTRUCTORS --------------------------- - - public CommandAddHashtag(MainActivity activity, String hashtag) { - super(activity); - this.hashtag = hashtag; - } - - // --------------------- GETTER / SETTER METHODS --------------------- - - @Override - public String getText() { - return "#" + hashtag; - } - - // -------------------------- OTHER METHODS -------------------------- - - @Override - public boolean execute() { - getActivity().getWorld().getPostState().beginTransaction().appendText(" #" + hashtag).commit(); - return true; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.kt b/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.kt new file mode 100644 index 00000000..5d8077d5 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandAddHashtag.kt @@ -0,0 +1,48 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2012-2014 lacolaco.net + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.lacolaco.smileessence.command + +import net.lacolaco.smileessence.activity.MainActivity + +class CommandAddHashtag +// --------------------------- CONSTRUCTORS --------------------------- + +(activity: MainActivity, + // ------------------------------ FIELDS ------------------------------ + + private val hashtag: String) : Command(activity) { + + // --------------------- GETTER / SETTER METHODS --------------------- + + override val text: String + get() = "#" + hashtag + + // -------------------------- OTHER METHODS -------------------------- + + override fun execute(): Boolean { + activity.world.postState.beginTransaction().appendText(" #" + hashtag).commit() + return true + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.java b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.java deleted file mode 100644 index c62e2601..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.command; - -import net.lacolaco.smileessence.activity.MainActivity; -import net.lacolaco.smileessence.util.IntentUtils; - -public class CommandOpenURL extends Command { - - // ------------------------------ FIELDS ------------------------------ - - private final String url; - - // --------------------------- CONSTRUCTORS --------------------------- - - public CommandOpenURL(MainActivity activity, String url) { - super(activity); - this.url = url; - } - - // --------------------- GETTER / SETTER METHODS --------------------- - - @Override - public String getText() { - return url; - } - - // -------------------------- OTHER METHODS -------------------------- - - @Override - public boolean execute() { - IntentUtils.openUri(getActivity(), url); - return true; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt new file mode 100644 index 00000000..b9150e12 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenURL.kt @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2012-2014 lacolaco.net + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.lacolaco.smileessence.command + +import net.lacolaco.smileessence.activity.MainActivity +import net.lacolaco.smileessence.util.IntentUtils + +class CommandOpenURL +// --------------------------- CONSTRUCTORS --------------------------- + +(activity: MainActivity, + // ------------------------------ FIELDS ------------------------------ + + // --------------------- GETTER / SETTER METHODS --------------------- + + override val text: String) : Command(activity) { + + // -------------------------- OTHER METHODS -------------------------- + + override fun execute(): Boolean { + IntentUtils.openUri(activity, text) + return true + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java deleted file mode 100644 index 600e0bc0..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.command; - -import net.lacolaco.smileessence.R; -import net.lacolaco.smileessence.activity.MainActivity; -import net.lacolaco.smileessence.twitter.task.Users; -import net.lacolaco.smileessence.view.DialogHelper; -import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment; - -public class CommandOpenUserDetail extends Command { - - // ------------------------------ FIELDS ------------------------------ - - private final String screenName; - - // --------------------------- CONSTRUCTORS --------------------------- - - public CommandOpenUserDetail(MainActivity activity, String screenName) { - super(activity); - this.screenName = screenName; - } - - // --------------------- GETTER / SETTER METHODS --------------------- - - @Override - public String getText() { - return String.format("@%s", screenName); - } - - // -------------------------- OTHER METHODS -------------------------- - - @Override - public boolean execute() { - new Users.GetTask(getActivity().getWorld().getAccount(), screenName) - .onDoneUI(user -> { - UserDetailDialogFragment fragment = new UserDetailDialogFragment(); - fragment.setUserID(user.getId()); - DialogHelper.showDialog(getActivity(), fragment); - }) - .onFail(x -> getActivity().getWorld().notifyError(R.string.notice_error_show_user)) - .execute(); - - return false; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.kt b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.kt new file mode 100644 index 00000000..89d5d2ef --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.kt @@ -0,0 +1,58 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2012-2014 lacolaco.net + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.lacolaco.smileessence.command + +import net.lacolaco.smileessence.R +import net.lacolaco.smileessence.activity.MainActivity +import net.lacolaco.smileessence.twitter.task.Users +import net.lacolaco.smileessence.view.DialogHelper +import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment + +class CommandOpenUserDetail +// --------------------------- CONSTRUCTORS --------------------------- + +(activity: MainActivity, + // ------------------------------ FIELDS ------------------------------ + + private val screenName: String) : Command(activity) { + + // --------------------- GETTER / SETTER METHODS --------------------- + + override val text: String + get() = String.format("@%s", screenName) + + // -------------------------- OTHER METHODS -------------------------- + + override fun execute(): Boolean { + Users.GetTask(activity.world.account, screenName) + .onDoneUI { user -> + DialogHelper.showDialog(activity, UserDetailDialogFragment.newInstance(user)) + } + .onFail { x -> activity.world.notifyError(R.string.notice_error_show_user) } + .execute() + + return false + } +} -- cgit v1.2.3