Loading app/src/main/java/net/fabiszewski/ulogger/DbAccess.java +12 −0 Original line number Diff line number Diff line Loading @@ -464,6 +464,18 @@ class DbAccess implements AutoCloseable { } } /** * Get current track id. * * @param context Context * @return Track id, zero if no track with valid id in database */ static int getTrackId(Context context) { try (DbAccess dbAccess = getOpenInstance(context)) { return dbAccess.getTrackId(); } } /** * Update current track, set id. * Loading app/src/main/java/net/fabiszewski/ulogger/MainActivity.java +2 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ public class MainActivity extends AppCompatActivity private final static int RESULT_GPX_EXPORT = 2; public final static String UPDATED_PREFS = "extra_updated_prefs"; public String preferenceHost; public String preferenceUnits; public long preferenceMinTimeMillis; public boolean preferenceLiveSync; Loading Loading @@ -161,6 +162,7 @@ public class MainActivity extends AppCompatActivity preferenceUnits = prefs.getString(SettingsActivity.KEY_UNITS, getString(R.string.pref_units_default)); preferenceMinTimeMillis = Long.parseLong(prefs.getString(SettingsActivity.KEY_MIN_TIME, getString(R.string.pref_mintime_default))) * 1000; preferenceLiveSync = prefs.getBoolean(SettingsActivity.KEY_LIVE_SYNC, false); preferenceHost = prefs.getString(SettingsActivity.KEY_HOST, "").replaceAll("/+$", ""); } /** Loading app/src/main/java/net/fabiszewski/ulogger/MainFragment.java +57 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.pm.PackageManager; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; Loading Loading @@ -74,6 +75,7 @@ public class MainFragment extends Fragment { private TextView locLabel; private TextView locLed; private SwipeSwitch switchLogger; private Button buttonShare; private PorterDuffColorFilter redFilter; private PorterDuffColorFilter greenFilter; Loading Loading @@ -102,6 +104,7 @@ public class MainFragment extends Fragment { Button buttonWaypoint = layout.findViewById(R.id.buttonWaypoint); Button buttonUpload = layout.findViewById(R.id.buttonUpload); Button buttonNewTrack = layout.findViewById(R.id.buttonNewTrack); buttonShare = layout.findViewById(R.id.buttonShare); syncErrorLabel = layout.findViewById(R.id.sync_error); syncLabel = layout.findViewById(R.id.sync_status); syncLed = layout.findViewById(R.id.sync_led); Loading @@ -113,6 +116,7 @@ public class MainFragment extends Fragment { buttonWaypoint.setOnClickListener(this::addWaypoint); buttonUpload.setOnClickListener(this::uploadData); buttonNewTrack.setOnClickListener(this::newTrack); buttonShare.setOnClickListener(this::shareURL); layoutSummary.setOnClickListener(this::trackSummary); return layout; } Loading Loading @@ -245,6 +249,10 @@ public class MainFragment extends Fragment { } } /** * Show toast * @param text Text */ private void showToast(String text) { Context context = getContext(); if (context != null) { Loading @@ -253,11 +261,37 @@ public class MainFragment extends Fragment { } } /** * Share track URL * Called when the user clicks the share button * @param view View */ private void shareURL(View view) { Context context = view.getContext(); String trackName = DbAccess.getTrackName(context); int trackId = DbAccess.getTrackId(context); MainActivity activity = (MainActivity) requireActivity(); String host = activity.preferenceHost; if (trackId > 0 && host.length() > 0) { String trackUrl = host + "/#" + trackId; Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, trackUrl); sendIntent.putExtra(Intent.EXTRA_TITLE, trackName); sendIntent.setType("text/plain"); Intent shareIntent = Intent.createChooser(sendIntent, getString(R.string.share_link)); Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(Uri.parse(trackUrl)); shareIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{viewIntent}); startActivity(shareIntent); } } /** * Called when the user clicks the Upload button * @param view View */ private void uploadData(@SuppressWarnings("UnusedParameters") View view) { private void uploadData(View view) { Context context = view.getContext(); if (!SettingsFragment.isValidServerSetup(context)) { showToast(getString(R.string.provide_user_pass_url)); Loading Loading @@ -387,7 +421,9 @@ public class MainFragment extends Fragment { View view = getView(); if (view != null) { final TextView trackLabel = view.findViewById(R.id.newtrack_label); trackName = trackName == null ? "-" : trackName; if (trackName == null) { trackName = "-"; } trackLabel.setText(trackName); } } Loading Loading @@ -469,6 +505,7 @@ public class MainFragment extends Fragment { if (context == null) { return; } updateShareButton(); updateLocationLabel(LoggerService.lastUpdateRealtime()); // get sync status int count = DbAccess.countUnsynced(context); Loading @@ -482,6 +519,21 @@ public class MainFragment extends Fragment { updateSyncStatus(count); } /** * Update visibility of share button */ private void updateShareButton() { Context context = getContext(); if (context == null) { return; } if (DbAccess.getTrackId(context) > 0) { buttonShare.setVisibility(View.VISIBLE); } else { buttonShare.setVisibility(View.GONE); } } /** * Set status led color * @param led Led text view Loading Loading @@ -615,6 +667,9 @@ public class MainFragment extends Fragment { showToast(getString(R.string.uploading_done)); isUploading = false; } if (buttonShare.getVisibility() == View.GONE) { buttonShare.setVisibility(View.VISIBLE); } break; case (WebSyncService.BROADCAST_SYNC_FAILED): { updateSyncStatus(DbAccess.countUnsynced(context)); Loading app/src/main/res/drawable/ic_share_white_24.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <!-- ~ Copyright (c) 2020 Bartek Fabiszewski ~ http://www.fabiszewski.net ~ ~ This file is part of μlogger-android. ~ Licensed under GPL, either version 3, or any later. ~ See <http://www.gnu.org/licenses/> ~ Material Design icon by Google. ~ Released under Apache License 2.0. --> <vector android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/> </vector> app/src/main/res/drawable/share_button_inset.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (c) 2020 Bartek Fabiszewski ~ http://www.fabiszewski.net ~ ~ This file is part of μlogger-android. ~ Licensed under GPL, either version 3, or any later. ~ See <http://www.gnu.org/licenses/> --> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/ic_share_white_24" android:insetTop="10dp" android:insetLeft="10dp" android:insetRight="10dp" android:insetBottom="10dp" /> No newline at end of file Loading
app/src/main/java/net/fabiszewski/ulogger/DbAccess.java +12 −0 Original line number Diff line number Diff line Loading @@ -464,6 +464,18 @@ class DbAccess implements AutoCloseable { } } /** * Get current track id. * * @param context Context * @return Track id, zero if no track with valid id in database */ static int getTrackId(Context context) { try (DbAccess dbAccess = getOpenInstance(context)) { return dbAccess.getTrackId(); } } /** * Update current track, set id. * Loading
app/src/main/java/net/fabiszewski/ulogger/MainActivity.java +2 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ public class MainActivity extends AppCompatActivity private final static int RESULT_GPX_EXPORT = 2; public final static String UPDATED_PREFS = "extra_updated_prefs"; public String preferenceHost; public String preferenceUnits; public long preferenceMinTimeMillis; public boolean preferenceLiveSync; Loading Loading @@ -161,6 +162,7 @@ public class MainActivity extends AppCompatActivity preferenceUnits = prefs.getString(SettingsActivity.KEY_UNITS, getString(R.string.pref_units_default)); preferenceMinTimeMillis = Long.parseLong(prefs.getString(SettingsActivity.KEY_MIN_TIME, getString(R.string.pref_mintime_default))) * 1000; preferenceLiveSync = prefs.getBoolean(SettingsActivity.KEY_LIVE_SYNC, false); preferenceHost = prefs.getString(SettingsActivity.KEY_HOST, "").replaceAll("/+$", ""); } /** Loading
app/src/main/java/net/fabiszewski/ulogger/MainFragment.java +57 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.pm.PackageManager; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; Loading Loading @@ -74,6 +75,7 @@ public class MainFragment extends Fragment { private TextView locLabel; private TextView locLed; private SwipeSwitch switchLogger; private Button buttonShare; private PorterDuffColorFilter redFilter; private PorterDuffColorFilter greenFilter; Loading Loading @@ -102,6 +104,7 @@ public class MainFragment extends Fragment { Button buttonWaypoint = layout.findViewById(R.id.buttonWaypoint); Button buttonUpload = layout.findViewById(R.id.buttonUpload); Button buttonNewTrack = layout.findViewById(R.id.buttonNewTrack); buttonShare = layout.findViewById(R.id.buttonShare); syncErrorLabel = layout.findViewById(R.id.sync_error); syncLabel = layout.findViewById(R.id.sync_status); syncLed = layout.findViewById(R.id.sync_led); Loading @@ -113,6 +116,7 @@ public class MainFragment extends Fragment { buttonWaypoint.setOnClickListener(this::addWaypoint); buttonUpload.setOnClickListener(this::uploadData); buttonNewTrack.setOnClickListener(this::newTrack); buttonShare.setOnClickListener(this::shareURL); layoutSummary.setOnClickListener(this::trackSummary); return layout; } Loading Loading @@ -245,6 +249,10 @@ public class MainFragment extends Fragment { } } /** * Show toast * @param text Text */ private void showToast(String text) { Context context = getContext(); if (context != null) { Loading @@ -253,11 +261,37 @@ public class MainFragment extends Fragment { } } /** * Share track URL * Called when the user clicks the share button * @param view View */ private void shareURL(View view) { Context context = view.getContext(); String trackName = DbAccess.getTrackName(context); int trackId = DbAccess.getTrackId(context); MainActivity activity = (MainActivity) requireActivity(); String host = activity.preferenceHost; if (trackId > 0 && host.length() > 0) { String trackUrl = host + "/#" + trackId; Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, trackUrl); sendIntent.putExtra(Intent.EXTRA_TITLE, trackName); sendIntent.setType("text/plain"); Intent shareIntent = Intent.createChooser(sendIntent, getString(R.string.share_link)); Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(Uri.parse(trackUrl)); shareIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{viewIntent}); startActivity(shareIntent); } } /** * Called when the user clicks the Upload button * @param view View */ private void uploadData(@SuppressWarnings("UnusedParameters") View view) { private void uploadData(View view) { Context context = view.getContext(); if (!SettingsFragment.isValidServerSetup(context)) { showToast(getString(R.string.provide_user_pass_url)); Loading Loading @@ -387,7 +421,9 @@ public class MainFragment extends Fragment { View view = getView(); if (view != null) { final TextView trackLabel = view.findViewById(R.id.newtrack_label); trackName = trackName == null ? "-" : trackName; if (trackName == null) { trackName = "-"; } trackLabel.setText(trackName); } } Loading Loading @@ -469,6 +505,7 @@ public class MainFragment extends Fragment { if (context == null) { return; } updateShareButton(); updateLocationLabel(LoggerService.lastUpdateRealtime()); // get sync status int count = DbAccess.countUnsynced(context); Loading @@ -482,6 +519,21 @@ public class MainFragment extends Fragment { updateSyncStatus(count); } /** * Update visibility of share button */ private void updateShareButton() { Context context = getContext(); if (context == null) { return; } if (DbAccess.getTrackId(context) > 0) { buttonShare.setVisibility(View.VISIBLE); } else { buttonShare.setVisibility(View.GONE); } } /** * Set status led color * @param led Led text view Loading Loading @@ -615,6 +667,9 @@ public class MainFragment extends Fragment { showToast(getString(R.string.uploading_done)); isUploading = false; } if (buttonShare.getVisibility() == View.GONE) { buttonShare.setVisibility(View.VISIBLE); } break; case (WebSyncService.BROADCAST_SYNC_FAILED): { updateSyncStatus(DbAccess.countUnsynced(context)); Loading
app/src/main/res/drawable/ic_share_white_24.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <!-- ~ Copyright (c) 2020 Bartek Fabiszewski ~ http://www.fabiszewski.net ~ ~ This file is part of μlogger-android. ~ Licensed under GPL, either version 3, or any later. ~ See <http://www.gnu.org/licenses/> ~ Material Design icon by Google. ~ Released under Apache License 2.0. --> <vector android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/> </vector>
app/src/main/res/drawable/share_button_inset.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (c) 2020 Bartek Fabiszewski ~ http://www.fabiszewski.net ~ ~ This file is part of μlogger-android. ~ Licensed under GPL, either version 3, or any later. ~ See <http://www.gnu.org/licenses/> --> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/ic_share_white_24" android:insetTop="10dp" android:insetLeft="10dp" android:insetRight="10dp" android:insetBottom="10dp" /> No newline at end of file