diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2014-05-28 07:02:08 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2014-05-28 07:02:08 +0200 |
commit | 41eb2aa0afe0fad2e23387a702b29f2eef8fec6c (patch) | |
tree | be480f2eec98cb2e0e5101bbdf17e0d6ddddcf22 /main | |
parent | 9dd3dc16cdd31a22b0633ca3d8c08a1c5209ce12 (diff) | |
download | cgeo-41eb2aa0afe0fad2e23387a702b29f2eef8fec6c.zip cgeo-41eb2aa0afe0fad2e23387a702b29f2eef8fec6c.tar.gz cgeo-41eb2aa0afe0fad2e23387a702b29f2eef8fec6c.tar.bz2 |
#3903: send button in actionbar, signature as template
Diffstat (limited to 'main')
-rw-r--r-- | main/res/drawable-mdpi/ic_menu_send.png | bin | 0 -> 920 bytes | |||
-rw-r--r-- | main/res/layout/logcache_activity.xml | 4 | ||||
-rw-r--r-- | main/res/menu/abstract_logging_activity.xml | 9 | ||||
-rw-r--r-- | main/res/values/strings.xml | 1 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/AbstractLoggingActivity.java | 11 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/LogCacheActivity.java | 72 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/settings/Settings.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/ui/dialog/Dialogs.java | 14 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/utils/LogTemplateProvider.java | 6 |
9 files changed, 56 insertions, 63 deletions
diff --git a/main/res/drawable-mdpi/ic_menu_send.png b/main/res/drawable-mdpi/ic_menu_send.png Binary files differnew file mode 100644 index 0000000..06b4717 --- /dev/null +++ b/main/res/drawable-mdpi/ic_menu_send.png diff --git a/main/res/layout/logcache_activity.xml b/main/res/layout/logcache_activity.xml index 28e5eb9..f38795d 100644 --- a/main/res/layout/logcache_activity.xml +++ b/main/res/layout/logcache_activity.xml @@ -125,10 +125,6 @@ style="@style/button_full" android:text="@string/log_image_attach" /> - <Button - android:id="@+id/post" - style="@style/button_full" - android:text="@string/log_post" /> <RelativeLayout style="@style/separator_horizontal_layout" > diff --git a/main/res/menu/abstract_logging_activity.xml b/main/res/menu/abstract_logging_activity.xml index a7841a5..7577cde 100644 --- a/main/res/menu/abstract_logging_activity.xml +++ b/main/res/menu/abstract_logging_activity.xml @@ -3,10 +3,11 @@ xmlns:cgeo="http://schemas.android.com/apk/res-auto"> <item - android:id="@+id/menu_signature" - android:icon="@drawable/ic_menu_edit" - android:title="@string/init_signature" - cgeo:showAsAction="ifRoom|withText"> + android:id="@+id/menu_send" + android:icon="@drawable/ic_menu_send" + android:title="@string/send" + android:enabled="true" + cgeo:showAsAction="ifRoom|withText"> <!-- enabled=true, we show a message if logging is not possible --> </item> <item android:id="@+id/menu_templates" diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index bd7ef2b..ab41c29 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -1289,5 +1289,6 @@ <!-- shortcuts --> <string name="cgeo_shortcut">c:geo shortcut</string> <string name="create_shortcut">Create shortcut</string> + <string name="send">Send</string> </resources> diff --git a/main/src/cgeo/geocaching/AbstractLoggingActivity.java b/main/src/cgeo/geocaching/AbstractLoggingActivity.java index 75dc3bf..1868491 100644 --- a/main/src/cgeo/geocaching/AbstractLoggingActivity.java +++ b/main/src/cgeo/geocaching/AbstractLoggingActivity.java @@ -7,13 +7,10 @@ import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.connector.gc.GCSmiliesProvider; import cgeo.geocaching.connector.gc.GCSmiliesProvider.Smiley; import cgeo.geocaching.connector.trackable.TravelBugConnector; -import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.LogTemplateProvider; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; import cgeo.geocaching.utils.LogTemplateProvider.LogTemplate; -import org.apache.commons.lang3.StringUtils; - import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; @@ -40,9 +37,6 @@ public abstract class AbstractLoggingActivity extends AbstractActionBarActivity @Override public boolean onPrepareOptionsMenu(Menu menu) { - final boolean signatureAvailable = StringUtils.isNotBlank(Settings.getSignature()); - menu.findItem(R.id.menu_signature).setVisible(signatureAvailable); - boolean smileyVisible = false; final Geocache cache = getLogContext().getCache(); if (cache != null && ConnectorFactory.getConnector(cache).equals(GCConnector.getInstance())) { @@ -62,11 +56,6 @@ public abstract class AbstractLoggingActivity extends AbstractActionBarActivity public boolean onOptionsItemSelected(MenuItem item) { final int id = item.getItemId(); - if (id == R.id.menu_signature) { - insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), getLogContext()), true); - return true; - } - final LogTemplate template = LogTemplateProvider.getTemplate(id); if (template != null) { insertIntoLog(template.getValue(getLogContext()), true); diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java index 08b90a5..d604882 100644 --- a/main/src/cgeo/geocaching/LogCacheActivity.java +++ b/main/src/cgeo/geocaching/LogCacheActivity.java @@ -32,6 +32,7 @@ import android.net.Uri; import android.os.Bundle; import android.util.SparseArray; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.CheckBox; @@ -65,7 +66,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia private String text = null; private List<LogType> possibleLogTypes = new ArrayList<LogType>(); private List<TrackableLog> trackables = null; - private Button postButton = null; private CheckBox tweetCheck = null; private LinearLayout tweetBox = null; private LinearLayout logPasswordBox = null; @@ -81,6 +81,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia private String imageCaption; private String imageDescription; private Uri imageUri; + private boolean sendButtonEnabled; public void onLoadFinished() { @@ -191,32 +192,8 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia } private void enablePostButton(boolean enabled) { - postButton.setEnabled(enabled); - if (enabled) { - postButton.setOnClickListener(new PostListener()); - } - else { - postButton.setOnTouchListener(null); - postButton.setOnClickListener(null); - } - updatePostButtonText(); - } - - private void updatePostButtonText() { - postButton.setText(getPostButtonText()); - } - - private String getPostButtonText() { - if (!postButton.isEnabled()) { - return res.getString(R.string.log_post_not_possible); - } - if (!GCVote.isVotingPossible(cache)) { - return res.getString(R.string.log_post); - } - if (GCVote.isValidRating(rating)) { - return res.getString(R.string.log_post_rate) + " " + GCVote.getRatingText(rating) + "*"; - } - return res.getString(R.string.log_post_no_rate); + sendButtonEnabled = enabled; + invalidateOptionsMenuCompatible(); } @Override @@ -245,7 +222,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia } // Get ids for later use - postButton = (Button) findViewById(R.id.post); tweetBox = (LinearLayout) findViewById(R.id.tweet_box); tweetCheck = (CheckBox) findViewById(R.id.tweet); logPasswordBox = (LinearLayout) findViewById(R.id.log_password_box); @@ -277,7 +253,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache, null)), false); } } - updatePostButtonText(); updateImageButton(); enablePostButton(false); @@ -353,7 +328,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia ratingBar.setRating(rating); } label.setText(GCVote.getDescription(rating)); - updatePostButtonText(); } }); } @@ -435,8 +409,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia updateTweetBox(type); updateLogPasswordBox(type); - - updatePostButtonText(); } private void updateTweetBox(LogType type) { @@ -465,16 +437,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia } } - private class PostListener implements View.OnClickListener { - @Override - public void onClick(View arg0) { - final String message = res.getString(StringUtils.isBlank(imageUri.getPath()) ? - R.string.log_saving : - R.string.log_saving_and_uploading); - new Poster(LogCacheActivity.this, message).execute(currentLogText(), currentLogPassword()); - } - } - private class Poster extends AsyncTaskWithProgress<String, StatusCode> { public Poster(final Activity activity, final String progressMessage) { @@ -680,4 +642,30 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia imageButton.setVisibility(View.GONE); } } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_send: + sendLog(); + return true; + + default: + break; + } + + return super.onOptionsItemSelected(item); + } + + private void sendLog() { + if (!sendButtonEnabled) { + Dialogs.message(this, R.string.log_post_not_possible); + } + else { + final String message = res.getString(StringUtils.isBlank(imageUri.getPath()) ? + R.string.log_saving : + R.string.log_saving_and_uploading); + new Poster(LogCacheActivity.this, message).execute(currentLogText(), currentLogPassword()); + } + } } diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java index 474558d..9de272b 100644 --- a/main/src/cgeo/geocaching/settings/Settings.java +++ b/main/src/cgeo/geocaching/settings/Settings.java @@ -374,7 +374,7 @@ public class Settings { } public static String getSignature() { - return getString(R.string.pref_signature, null); + return getString(R.string.pref_signature, StringUtils.EMPTY); } public static boolean setCookieStore(final String cookies) { diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java index cb8926a..6a2f9a5 100644 --- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java +++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java @@ -218,7 +218,19 @@ public final class Dialogs { /** * Show a message dialog with a single "OK" button. - * + * + * @param context + * activity owning the dialog + * @param message + * message dialog content + */ + public static void message(final Activity context, final int message) { + message(context, null, getString(message)); + } + + /** + * Show a message dialog with a single "OK" button. + * * @param context * activity owning the dialog * @param title diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java index 04433c3..2d4fc80 100644 --- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java +++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java @@ -221,6 +221,12 @@ public final class LogTemplateProvider { return StringUtils.EMPTY; } }); + templates.add(new LogTemplate("SIGNATURE", R.string.init_signature) { + @Override + public String getValue(LogContext context) { + return StringUtils.defaultString(Settings.getSignature()); + } + }); return templates; } |