new story menubar; effectively close #553

This commit is contained in:
Austin Huang 2021-04-03 12:29:56 -04:00
parent 04ee3883ea
commit 4c800835c3
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 69 additions and 18 deletions

View File

@ -137,14 +137,14 @@ public class StoryViewerFragment extends Fragment {
private String[] mentions; private String[] mentions;
private QuizModel quiz; private QuizModel quiz;
private SliderModel slider; private SliderModel slider;
private MenuItem menuDownload; private MenuItem menuDownload, menuDm, menuProfile;
private MenuItem menuDm;
private SimpleExoPlayer player; private SimpleExoPlayer player;
// private boolean isHashtag; // private boolean isHashtag;
// private boolean isLoc; // private boolean isLoc;
// private String highlight; // private String highlight;
private String actionBarTitle; private String actionBarTitle, actionBarSubtitle;
private boolean fetching = false, sticking = false, shouldRefresh = true; private boolean fetching = false, sticking = false, shouldRefresh = true;
private boolean downloadVisible = false, dmVisible = false, profileVisible = true;
private int currentFeedStoryIndex; private int currentFeedStoryIndex;
private double sliderValue; private double sliderValue;
private StoriesViewModel storiesViewModel; private StoriesViewModel storiesViewModel;
@ -195,8 +195,10 @@ public class StoryViewerFragment extends Fragment {
menuInflater.inflate(R.menu.story_menu, menu); menuInflater.inflate(R.menu.story_menu, menu);
menuDownload = menu.findItem(R.id.action_download); menuDownload = menu.findItem(R.id.action_download);
menuDm = menu.findItem(R.id.action_dms); menuDm = menu.findItem(R.id.action_dms);
menuDownload.setVisible(false); menuProfile = menu.findItem(R.id.action_profile);
menuDm.setVisible(false); menuDownload.setVisible(downloadVisible);
menuDm.setVisible(dmVisible);
menuProfile.setVisible(profileVisible);
} }
@Override @Override
@ -215,7 +217,8 @@ public class StoryViewerFragment extends Fragment {
else else
ActivityCompat.requestPermissions(requireActivity(), DownloadUtils.PERMS, 8020); ActivityCompat.requestPermissions(requireActivity(), DownloadUtils.PERMS, 8020);
return true; return true;
} else if (itemId == R.id.action_dms) { }
if (itemId == R.id.action_dms) {
final EditText input = new EditText(context); final EditText input = new EditText(context);
input.setHint(R.string.reply_hint); input.setHint(R.string.reply_hint);
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
@ -259,6 +262,9 @@ public class StoryViewerFragment extends Fragment {
.show(); .show();
return true; return true;
} }
if (itemId == R.id.action_profile) {
openProfile("@" + currentStory.getUsername());
}
return false; return false;
} }
@ -281,7 +287,9 @@ public class StoryViewerFragment extends Fragment {
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
actionBar.setTitle(actionBarTitle); actionBar.setTitle(actionBarTitle);
actionBar.setSubtitle(actionBarSubtitle);
} }
setHasOptionsMenu(true);
} }
@Override @Override
@ -697,6 +705,10 @@ public class StoryViewerFragment extends Fragment {
lastSlidePos = 0; lastSlidePos = 0;
if (menuDownload != null) menuDownload.setVisible(false); if (menuDownload != null) menuDownload.setVisible(false);
if (menuDm != null) menuDm.setVisible(false); if (menuDm != null) menuDm.setVisible(false);
if (menuProfile != null) menuProfile.setVisible(false);
downloadVisible = false;
dmVisible = false;
profileVisible = false;
binding.imageViewer.setController(null); binding.imageViewer.setController(null);
releasePlayer(); releasePlayer();
String currentStoryMediaId = null; String currentStoryMediaId = null;
@ -846,7 +858,6 @@ public class StoryViewerFragment extends Fragment {
final MediaItemType itemType = currentStory.getItemType(); final MediaItemType itemType = currentStory.getItemType();
if (menuDownload != null) menuDownload.setVisible(false);
url = itemType == MediaItemType.MEDIA_TYPE_IMAGE ? currentStory.getStoryUrl() : currentStory.getVideoUrl(); url = itemType == MediaItemType.MEDIA_TYPE_IMAGE ? currentStory.getStoryUrl() : currentStory.getVideoUrl();
if (itemType != MediaItemType.MEDIA_TYPE_LIVE) { if (itemType != MediaItemType.MEDIA_TYPE_LIVE) {
@ -900,9 +911,10 @@ public class StoryViewerFragment extends Fragment {
else setupImage(); else setupImage();
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
actionBarSubtitle = Utils.datetimeParser.format(new Date(currentStory.getTimestamp() * 1000L));
if (actionBar != null) { if (actionBar != null) {
try { try {
actionBar.setSubtitle(Utils.datetimeParser.format(new Date(currentStory.getTimestamp() * 1000L))); actionBar.setSubtitle(actionBarSubtitle);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "refreshStory: ", e); Log.e(TAG, "refreshStory: ", e);
} }
@ -948,11 +960,17 @@ public class StoryViewerFragment extends Fragment {
final ImageInfo imageInfo, final ImageInfo imageInfo,
final Animatable animatable) { final Animatable animatable) {
if (menuDownload != null) { if (menuDownload != null) {
downloadVisible = true;
menuDownload.setVisible(true); menuDownload.setVisible(true);
} }
if (currentStory.canReply() && menuDm != null) { if (currentStory.canReply() && menuDm != null) {
dmVisible = true;
menuDm.setVisible(true); menuDm.setVisible(true);
} }
if (!TextUtils.isEmpty(currentStory.getUsername())) {
profileVisible = true;
menuProfile.setVisible(true);
}
binding.progressView.setVisibility(View.GONE); binding.progressView.setVisibility(View.GONE);
} }
}) })
@ -982,9 +1000,18 @@ public class StoryViewerFragment extends Fragment {
@Nullable final MediaSource.MediaPeriodId mediaPeriodId, @Nullable final MediaSource.MediaPeriodId mediaPeriodId,
@NonNull final LoadEventInfo loadEventInfo, @NonNull final LoadEventInfo loadEventInfo,
@NonNull final MediaLoadData mediaLoadData) { @NonNull final MediaLoadData mediaLoadData) {
if (menuDownload != null) menuDownload.setVisible(true); if (menuDownload != null) {
if (currentStory.canReply() && menuDm != null) downloadVisible = true;
menuDownload.setVisible(true);
}
if (currentStory.canReply() && menuDm != null) {
dmVisible = true;
menuDm.setVisible(true); menuDm.setVisible(true);
}
if (!TextUtils.isEmpty(currentStory.getUsername()) && menuProfile != null) {
profileVisible = true;
menuProfile.setVisible(true);
}
binding.progressView.setVisibility(View.GONE); binding.progressView.setVisibility(View.GONE);
} }
@ -993,9 +1020,18 @@ public class StoryViewerFragment extends Fragment {
@Nullable final MediaSource.MediaPeriodId mediaPeriodId, @Nullable final MediaSource.MediaPeriodId mediaPeriodId,
@NonNull final LoadEventInfo loadEventInfo, @NonNull final LoadEventInfo loadEventInfo,
@NonNull final MediaLoadData mediaLoadData) { @NonNull final MediaLoadData mediaLoadData) {
if (menuDownload != null) menuDownload.setVisible(true); if (menuDownload != null) {
if (currentStory.canReply() && menuDm != null) downloadVisible = true;
menuDownload.setVisible(true);
}
if (currentStory.canReply() && menuDm != null) {
dmVisible = true;
menuDm.setVisible(true); menuDm.setVisible(true);
}
if (!TextUtils.isEmpty(currentStory.getUsername()) && menuProfile != null) {
profileVisible = true;
menuProfile.setVisible(true);
}
binding.progressView.setVisibility(View.VISIBLE); binding.progressView.setVisibility(View.VISIBLE);
} }
@ -1014,8 +1050,18 @@ public class StoryViewerFragment extends Fragment {
@NonNull final MediaLoadData mediaLoadData, @NonNull final MediaLoadData mediaLoadData,
@NonNull final IOException error, @NonNull final IOException error,
final boolean wasCanceled) { final boolean wasCanceled) {
if (menuDownload != null) menuDownload.setVisible(false); if (menuDownload != null) {
if (menuDm != null) menuDm.setVisible(false); downloadVisible = false;
menuDownload.setVisible(false);
}
if (menuDm != null) {
dmVisible = false;
menuDm.setVisible(false);
}
if (menuProfile != null) {
profileVisible = false;
menuProfile.setVisible(false);
}
binding.progressView.setVisibility(View.GONE); binding.progressView.setVisibility(View.GONE);
} }
}); });

View File

@ -5,13 +5,18 @@
<item <item
android:id="@+id/action_dms" android:id="@+id/action_dms"
android:icon="@drawable/ic_round_send_24" android:icon="@drawable/ic_round_send_24"
android:title="@string/action_dms" android:title="@string/reply_story"
android:titleCondensed="@string/action_dms" android:titleCondensed="@string/reply_story"
app:showAsAction="always" /> app:showAsAction="never" />
<item
android:id="@+id/action_profile"
android:title="@string/open_profile"
android:titleCondensed="@string/open_profile"
app:showAsAction="never" />
<item <item
android:id="@+id/action_download" android:id="@+id/action_download"
android:icon="@drawable/ic_download" android:icon="@drawable/ic_download"
android:title="@string/action_download" android:title="@string/action_download"
android:titleCondensed="@string/action_download" android:titleCondensed="@string/action_download"
app:showAsAction="always" /> app:showAsAction="never" />
</menu> </menu>