-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Override on destory to retain fragments #2979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import android.os.Bundle; | ||
| import android.text.TextUtils; | ||
| import android.util.Log; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused import? |
||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
@@ -16,6 +17,7 @@ | |
| import androidx.recyclerview.widget.LinearLayoutManager; | ||
| import androidx.recyclerview.widget.RecyclerView; | ||
|
|
||
| import com.github.chrisbanes.photoview.OnScaleChangedListener; | ||
| import com.github.chrisbanes.photoview.PhotoView; | ||
| import com.jakewharton.rxbinding2.widget.RxTextView; | ||
|
|
||
|
|
@@ -155,6 +157,19 @@ private void init() { | |
| } else { | ||
| btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE); | ||
| } | ||
|
|
||
| attachImageViewScaleChangeListener(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change seems irrelevant to the rest of the patch. Mention it in the commit message? Or separate to its own patch? It's a best practice to make each commit have an easily understandable single purpose: |
||
| } | ||
|
|
||
| /** | ||
| * Attaches the scale change listener to the image view | ||
| */ | ||
| private void attachImageViewScaleChangeListener() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename the method to something like Ideally a reader of the |
||
| photoViewBackgroundImage.setOnScaleChangeListener( | ||
| (scaleFactor, focusX, focusY) -> { | ||
| //Whenever the uses plays with the image, lets collapse the media detail container | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/uses/user Also, this is actually a comment that would be nice to include in the Javadoc, to give a reason why this method is there. |
||
| expandCollapseLlMediaDetail(false); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -310,7 +325,15 @@ public void onDestroyView() { | |
|
|
||
| @OnClick(R.id.rl_container_title) | ||
| public void onRlContainerTitleClicked() { | ||
| llContainerMediaDetail.setVisibility(isExpanded ? View.GONE : View.VISIBLE); | ||
| expandCollapseLlMediaDetail(!isExpanded); | ||
| } | ||
|
|
||
| /** | ||
| * show hide media detail based on | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation nits:
Generally try to optimise the documentation writing for how it renders in the IDE (e.g. Ctrl-Q in Android Studio) or when the HTML javadoc is generated |
||
| * @param shouldExpand | ||
| */ | ||
| private void expandCollapseLlMediaDetail(boolean shouldExpand){ | ||
| llContainerMediaDetail.setVisibility(shouldExpand ? View.VISIBLE : View.GONE); | ||
| isExpanded = !isExpanded; | ||
| ibExpandCollapse.setRotation(ibExpandCollapse.getRotation() + 180); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit does not give context about why disabling the item destruction is needed, it would be good to at least document that.
The items are going to hold images right? Are you worried that keeping the images (or whatever is in the fragments) around can cause too much memory pressure? Why was a FragmentStatePagerAdapter used in the first place?
Looking at its documentation, there is a mention to FragmentPagerAdapter that does not do any memory clearing. Maybe refactor to use that as base class instead if you really want to disable that? The memory management is a defining feature of FragmentStatePagerAdapter, if would probably be easier to change the base class, and reduce the risks of introducing hard to track bugs.