Skip to content
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

timob-13864: add support for maps inside actionbar tab #5462

Merged
merged 3 commits into from
Mar 20, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package ti.modules.titanium.ui.widget.tabgroup;

import java.lang.ref.WeakReference;

import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiUIHelper;
Expand All @@ -23,15 +25,19 @@ public class TiUIActionBarTab extends TiUIAbstractTab {

private static final String TAG = "TiUIActionBarTab";
public static class TabFragment extends Fragment {
private View contentView;
private WeakReference<TiUIActionBarTab> tab;

public void setContentView(View view) {
contentView = view;
public TabFragment(TiUIActionBarTab tab) {
this.tab = new WeakReference<TiUIActionBarTab>(tab);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for weak references for the Tab.

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return contentView;
if (tab == null) {
return null;
} else {
return tab.get().getContentView();
}
}
}

Expand Down Expand Up @@ -87,8 +93,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
* will display the tab's content view.
*/
void initializeFragment() {
fragment = new TabFragment();
fragment.setContentView(getContentView());
fragment = new TabFragment(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ public boolean dispatchTouchEvent(MotionEvent ev)
setNativeView(container);

FragmentManager manager = ((FragmentActivity) activity).getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
Fragment tabFragment = manager.findFragmentById(android.R.id.tabcontent);
FragmentTransaction transaction = null;
//check if this map is opened inside an actionbar tab, which is another fragment
if (tabFragment != null) {
FragmentManager childManager = tabFragment.getChildFragmentManager();
transaction = childManager.beginTransaction();
} else {
transaction = manager.beginTransaction();
}
fragment = createFragment();
transaction.add(container.getId(), fragment);
transaction.commit();
Expand Down Expand Up @@ -69,7 +77,14 @@ public void release()
if (fragment != null) {
FragmentManager fragmentManager = fragment.getFragmentManager();
if (fragmentManager != null) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
FragmentTransaction transaction = null;
Fragment tabFragment = fragmentManager.findFragmentById(android.R.id.tabcontent);
if (tabFragment != null) {
FragmentManager childManager = tabFragment.getChildFragmentManager();
transaction = childManager.beginTransaction();
} else {
transaction = fragmentManager.beginTransaction();
}
transaction.remove(fragment);
transaction.commit();
}
Expand Down